[fpc-pascal] Linux - ExecuteProcess versus fpSystem
brian at meadows.pair.com
Fri Sep 9 01:40:12 CEST 2011
On 09/08/2011 01:07 PM, Marco van de Voort wrote:
> In our previous episode, Anton Shepelev said:
>> In the case of ExecuteProcess() parameter separation
>> takes place on FPC side, while with fpSystem() the
>> shell is responsible for it.
> Executeprocess has two forms. One does parameter separation,
> and one not, and directly passes the separated parameters to
> This was actually the reason for executeprocess.
>> Could a problem with
>> FPC's parameter separation algorithm be causing
> Maybe, but only when you use the wrong variant.
>> Can you post both the commands you are executing?
> Yes, that would be the best.
>> When I was learing processes, I wrote a unit to exe-
>> cute a command using fpExecv -- just as
>> ExecuteProcess() does. I'll dig it out and we'll see
>> how (and whether) it works with your examples.
> There should be no need for that.
OK, sorry for the delay in catching up with all the responses. I'll
roll everything into one message.
Why am I using a subprocess rather than writing a batch file? There's
a bunch of other processing going on, but none of it involves
manipulating the files other than a possible rename. It's selection of
which files to convert according to various criteria, elimination of
some duplicates, that sort of thing. It just seemed tidier to me to do
the whole lot in the program rather than doing most of the work then
write a batch file for the actual conversions.
What are the commands?
mpg321 -q -w "tempfile.wav" "inputfile.mp3"
oggenc -Q --output="outputfile.ogg" "tempfile.wav"
It makes no difference whether or not I use a full pathname for mpg321
and oggenc, and all the other files are in the current working
directory. Yes, there really are quotes round the filenames, the vast
majority of the real names have embedded spaces.
As regards oggenc being faulty and not working unless called from the
shell, no, that one hadn't occurred to me, not sure how to test it.
Running with strace. Eek! 6.5 MB of trace output. :) I think it's
found the problem, though. I get a bunch of
"ERROR: Multiple files specified when using stdin"
It's difficult to see why this should be the case. I have the program
name and the parameters set up as strings within my program. To switch
between the ExecuteProcess and fpSystem calls, I just commented out
the one I wasn't trying. The two lines of code are
Status := ExecuteProcess(CommandString, ParamString);
Status := fpSystem(CommandString+' '+ParamString);
CommandString just contains mog321 or oggenc (with or without the full
path) and ParamString is the rest of the commands I gave above.
Do I need to add a separator to the front of ParamString when using
ExecuteProcess? It wouldn't seem sensible to require it, since there
are the two parameters to ExecuteProcess versus the one for fpSystem,
but maybe that's it.
Thanks for the assistance so far, everyone.
More information about the fpc-pascal