[fpc-pascal] Re: Linux: How to execute a program, but not to wait until finishes
el.es.cr at gmail.com
Tue Jul 5 09:44:02 CEST 2011
On 04/07/2011 18:05, Marco van de Voort wrote:
> In our previous episode, Lukasz Sokol said:
>> ExecuteProcess('/bin/bash -c /my/path/to/exe &'); //
> First, the binary name is always separate, there are minimal two
You've snipped a ' :)' that was in the next line :)
> Moverover I would use the separate syntax, or use "" to signal that
> the /commandline my... & belongs together.
> So either (the better solution)
> executeprocess('/bin/bash',['-c','/my/path/to/exe &']);
> or the old syntax:
> executeprocess('/bin/bash,' -c "/my/path/to/exe &"');
> or using more unixy routines:
> fpsystem('/my/path/to/exe &');
> the old syntax has as disadvantage that in more complex cases gets
> problems with nested quoting. The last syntax uses the default system
> shell, which might not be bash (and bash might not be in /bin
> everywhere, when installed)
A day without learning something new, is a day lost ;)
> A 4th way is using TProcess, which in trunk now also has
> possibilities to specify arguments individually to avoid certain
> quoting problems.
I like this one.
>> I think you need to use fork
>> http://www.freepascal.org/docs-html/rtl/oldlinux/fork.html and then
>> one of the exec* procedures
>> (search for exec on this page, there is 6 of them related to linux
>> - Execl, Execle,Execlp,Execv,Execve,Execvp - that _do_not_return_
>> when called! that's why you need to use Fork())
> That's what executeprocess and the other ways do for you.
More information about the fpc-pascal