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
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
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
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
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
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;
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
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
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
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.
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
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
12 matches
Mail list logo