View Issue Details

IDProjectCategoryView StatusLast Update
0014446FPCFCLpublic2014-03-06 10:22
ReporterGraeme Geldenhuys Assigned ToMichael Van Canneyt  
Status closedResolutionfixed 
Platformx86_64 & i386OSUbuntu Linux 9.04 
Product Version2.3.1 
Target Version2.6.0Fixed in Version2.6.0 
Summary0014446: TProcess cannot execute a command
DescriptionThis email describes the issue.

----------[ forward ]----------------
Mattias Gaertner wrote:
> On Thu, 27 Aug 2009 11:23:52 +0200
> Graeme Geldenhuys <> wrote:
>> Hi,
>> As far as I know, Lazarus doesn't have a Thread List Window available.
>> So I am trying to setup and external tools menu item which will do
>> this for me, but I am have some problems with it.
>> This is the actual setup strings used for the external tool.
>> Program Filename:
>> /usr/bin/gnome-terminal
>> Parameters:
>> --title="Thread Monitor - $NameOnly($TargetFile())" --command="watch
>> -n.1 'ps -C $NameOnly($TargetFile()) -L -o pid,tid,pcpu,state'"
>> When I run Lazarus from the command line under Linux, this is the
>> output shown to stdout when I try and run my external tool.
>> [TExternalToolList.Run] CmdLine="/usr/bin/gnome-terminal
>> --title="Thread Monitor - project1" --command="watch -n.1 'ps -C
>> project1 -L -o pid,tid,pcpu,state'"" WorkDir=""
>> As far as I can see the macros used in the External Tool step was
>> converted correctly. I can even copy and paste the CmdLine without the
>> outer quotes and it executes fine from a teminal window. Yet, if I run
>> it from the Tools menu gnome-terminal gives an error. The error is:
>> "There was an error creating the child process for this terminal"
>> Anybody know what I am doing wrong?
> It is a bug in fcl-process/src/unix/ proc CommandToList
> used by TProcess.
> It only removes the outer ".
> Please report it.
> Mattias

I even tried putting my command in a executable shell script as shown below, and that did not work either.

----------[ ~/bin/lsthreads ]------------------
/usr/bin/gnome-terminal --title="Thread Monitor" \
   --command="watch -n.1 'ps -C ${1} -L -o pid,tid,pcpu,state'"
----------------[ end ]------------------

and here is a small test project...

--------[ small test program ]-------------
program project1;

{$mode objfpc}{$H+}

  Classes, process;
  t: TProcess;
  sl: TStringList;
  t := TProcess.Create(nil);
  t.Options := [poWaitOnExit];

  // this gives an error
// t.CommandLine := '/usr/bin/gnome-terminal --title="Thread Monitor - project1" --command="watch -n.1 ''ps -C project1 -L -o pid,tid,pcpu,state''" ';

  // this doesn't show anything
  t.CommandLine := 'lsthreads lazarus';

  // this one works
  //t.CommandLine := 'top';

  writeln('Press <ENTER> to continue...');
--------------[ end ]-------------------

TagsNo tags attached.
Fixed in Revision17379
Attached Files


related to 0012034 closedMichael Van Canneyt TProcess with poNewConsole on Linux always use XTerm as shell 


Michael Van Canneyt

2009-08-27 14:58

administrator   ~0030200

Can you be more specific ? What does not work ?
The TProcess works fine - otherwise Lazarus would not work.
- Please give an example that does not rely on exotic commands.
- Give the output of 'strace' when you execute the commands.
It will tell you which arguments are passed to the command.

Mattias Gaertner

2009-08-27 15:00

manager   ~0030201

This works:

This does not work:

Michael Van Canneyt

2009-08-27 15:18

administrator   ~0030202

Of course, the second is not supposed to work.

Quotes can be used to enclose complete arguments, not parts of arguments.

TProcess does not pretend to duplicate the shell's rules for quoting.

Mattias Gaertner

2009-08-27 15:29

manager   ~0030203

Last edited: 2009-08-27 15:30

Right you are:

Maybe it should be made more clear with something like:

"--param=some things"
is passed without the "" as one parameter
--param=some things

--param="some things"
is passed with the "" as one parameter
--param="some things"

Graeme Geldenhuys

2009-08-27 15:50

reporter   ~0030204

As Mattias mentioned... The parameter I am passing to the program has spaces in, so I had to enclose those with quotes. I expected the same when passing it to TProcess - as used in Lazarus External Tools setup.

--param="hello world"

This is what I need to pass to the program from the command prompt, so I would expect to pass the exact same to the TProcess.

Simple to test with an example. Create a simple program that outputs the ParamCount and lists the ParamStr() values. Create a GUI apps with a EditBox and a Run button. When Run is clicked it takes the value from the edit box and passes it to the TProcess.CommandLine property

The following is entered in a TEdit. <> brackets are used to show the begin and end of the text entered. The <> are not accually part of the text.

  <someapp --param="hello world">

This equates to one program: someapp
and one parameter: --param="hello world"

What TProcess seems to expect is the following:

  <someapp --param=Hello World>
  <someapp "--param=Hello World">

Here the first option equates to two parameters which is wrong. The second option is just not something that a general user would expect to enter, but clearly is what TProcess expects.

Michael Van Canneyt

2009-08-27 16:04

administrator   ~0030205

Since the current behaviour is correctly documented (see link provided by Mattias),
I consider this a feature request, and have modified the bugreport accordingly.
But for the same reason I also set the priority to low.

If you want a solution fast, I'll gladly accept and apply a patch :-)

Marco van de Voort

2009-11-06 13:21

manager   ~0031941

Last edited: 2010-02-14 16:54

A better solution anyway would be to work with an array (property) of arguments instead of a commandline as much as possible.

The commandline could be retained for compatibility and ease of use, but it makes it a lot easier to handle difficult cases with an unambigious system not needing any form of quoting.

It really simplified certain cases when executeprocess() with array of string was used vs the one commandline string approach.

Solving this with special purpose quoting will only make more odd ball cases turn up

Michael Van Canneyt

2011-04-27 23:34

administrator   ~0047853

Changed API so ApplicationName and CommandLine are deprecated.
New properties are 'Executable' and 'Parameters'

if CommandLine is set, it is automatically converted to the 2 new properties.
To use the new properties, clear the commandline property after the conversion was done.

CommandLine currently still takes precedence over Executable and Parameters, as long as it is set. In a future major version, it will be removed alltogether.

Issue History

Date Modified Username Field Change
2009-08-27 14:52 Graeme Geldenhuys New Issue
2009-08-27 14:57 Michael Van Canneyt Status new => assigned
2009-08-27 14:57 Michael Van Canneyt Assigned To => Michael Van Canneyt
2009-08-27 14:58 Michael Van Canneyt Note Added: 0030200
2009-08-27 14:58 Michael Van Canneyt Status assigned => feedback
2009-08-27 15:00 Mattias Gaertner Note Added: 0030201
2009-08-27 15:18 Michael Van Canneyt Note Added: 0030202
2009-08-27 15:29 Mattias Gaertner Note Added: 0030203
2009-08-27 15:30 Mattias Gaertner Note Edited: 0030203
2009-08-27 15:50 Graeme Geldenhuys Note Added: 0030204
2009-08-27 16:02 Michael Van Canneyt FPCOldBugId => 0
2009-08-27 16:02 Michael Van Canneyt Priority normal => low
2009-08-27 16:02 Michael Van Canneyt Severity minor => feature
2009-08-27 16:04 Michael Van Canneyt Note Added: 0030205
2009-11-06 13:21 Marco van de Voort Note Added: 0031941
2009-11-08 18:14 Marco van de Voort Note Edited: 0031941
2010-02-14 16:54 Marco van de Voort Note Edited: 0031941
2010-02-14 16:54 Marco van de Voort Note Edited: 0031941
2011-02-12 21:09 Marco van de Voort Relationship added related to 0012034
2011-04-27 23:34 Michael Van Canneyt Fixed in Revision => 17379
2011-04-27 23:34 Michael Van Canneyt Status feedback => resolved
2011-04-27 23:34 Michael Van Canneyt Fixed in Version => 2.5.1
2011-04-27 23:34 Michael Van Canneyt Resolution open => fixed
2011-04-27 23:34 Michael Van Canneyt Note Added: 0047853
2011-04-27 23:34 Michael Van Canneyt Target Version => 2.6.0
2011-12-01 13:23 Marco van de Voort Fixed in Version 2.5.1 => 2.6.0
2014-03-06 10:22 Michael Van Canneyt Status resolved => closed