RE : [fpc-devel] Running programs with output redirection

2011-07-17 Thread Ludo Brands
There seems to exist an issue with (output) redirection, when I try to run an external program from code. What I want to achieve is this: In a Win32 console I can run diff -r dir1 dir2 diff.txt When I use e.g. Exec('diff', args), diff complains about an excess argument, it works

RE : RE : [fpc-devel] Running programs with output redirection

2011-07-17 Thread Ludo Brands
Does there exist a simple way to run diff, and to redirect its output into an file? A batch file? Platform independence would be nice, of course. Start the shell instead of diff: exec('cmd','/c diff -r dir1 dir2 diff.txt'); The /c tells the shell to execute the command

RE : RE : RE : [fpc-devel] Running programs with output redirection

2011-07-17 Thread Ludo Brands
This is all windows though. Cross platform solution: Uses process ... p:=TProcess.Create(nil); {$IFDEF WIN32} p.CommandLine := 'cmd /c diff -r dir1 dir2 diff.txt'; {$ENDIF} {$IFDEF LINUX} p.CommandLine := 'bash -c diff -r dir1 dir2 diff.txt'; {$ENDIF} p.Execute; ... Ludo

Re: [fpc-devel] Running programs with output redirection

2011-07-17 Thread Hans-Peter Diettrich
Andrew Haines schrieb: The best way I know is described here: http://wiki.lazarus.freepascal.org/Executing_External_Programs#How_to_redirect_output_with_TProcess Thanks for the link, I didn't know before that redirecting is such a big issue. RunCommandAndDirectOutput('diff', '-r dir1

Re: [fpc-devel] Running programs with output redirection

2011-07-17 Thread Graeme Geldenhuys
On 16 July 2011 22:37, Hans-Peter Diettrich drdiettri...@aol.com wrote: Does there exist a simple way to run diff, and to redirect its output into an file? A batch file? Platform independence would be nice, of course. Execute diff with the two parameters via TProcess. Read the output as

Re: RE : RE : RE : [fpc-devel] Running programs with output redirection

2011-07-17 Thread Mark Morgan Lloyd
Ludo Brands wrote: This is all windows though. Cross platform solution: Uses process ... p:=TProcess.Create(nil); {$IFDEF WIN32} p.CommandLine := 'cmd /c diff -r dir1 dir2 diff.txt'; {$ENDIF} {$IFDEF LINUX} p.CommandLine := 'bash -c diff -r dir1 dir2 diff.txt'; {$ENDIF} p.Execute;

Re: RE : [fpc-devel] Running programs with output redirection

2011-07-17 Thread Hans-Peter Diettrich
Ludo Brands schrieb: Start the shell instead of diff: exec('cmd','/c diff -r dir1 dir2 diff.txt'); The /c tells the shell to execute the command and exit immediately. Thanks, this comes close to what I had in mind :-) But it looks quite platform dependent, like my other idea of invoking

Re: RE : RE : RE : [fpc-devel] Running programs with output redirection

2011-07-17 Thread Hans-Peter Diettrich
Ludo Brands schrieb: Cross platform solution: Uses process ... p:=TProcess.Create(nil); {$IFDEF WIN32} p.CommandLine := 'cmd /c diff -r dir1 dir2 diff.txt'; {$ENDIF} {$IFDEF LINUX} p.CommandLine := 'bash -c diff -r dir1 dir2 diff.txt'; {$ENDIF} p.Execute; Looks like this could be

Re: [fpc-devel] Running programs with output redirection

2011-07-17 Thread David W Noon
On Sun, 17 Jul 2011 09:51:12 +, Mark Morgan Lloyd wrote about Re: RE : RE : RE : [fpc-devel] Running programs with output redirection: Ludo Brands wrote: [snip] {$IFDEF LINUX} p.CommandLine := 'bash -c diff -r dir1 dir2 diff.txt'; {$ENDIF} p.Execute; Might be safer to refer to sh

Re: [fpc-devel] Running programs with output redirection

2011-07-17 Thread Andrew Haines
On 07/17/11 05:50, Hans-Peter Diettrich wrote: Andrew Haines schrieb: The best way I know is described here: http://wiki.lazarus.freepascal.org/Executing_External_Programs#How_to_redirect_output_with_TProcess Thanks for the link, I didn't know before that redirecting is such a big issue.

Re: [fpc-devel] Running programs with output redirection

2011-07-16 Thread Andrew Haines
On 07/16/11 16:37, Hans-Peter Diettrich wrote: There seems to exist an issue with (output) redirection, when I try to run an external program from code. What I want to achieve is this: In a Win32 console I can run diff -r dir1 dir2 diff.txt When I use e.g. Exec('diff', args), diff

Re: [fpc-devel] Running programs with output redirection

2011-07-16 Thread Sven Barth
On 16.07.2011 22:37, Hans-Peter Diettrich wrote: There seems to exist an issue with (output) redirection, when I try to run an external program from code. What I want to achieve is this: In a Win32 console I can run diff -r dir1 dir2 diff.txt When I use e.g. Exec('diff', args), diff