barko wrote:

I use this on linux and windows:

function Run(fexec,args:string; wait:boolean):boolean;
var ffexec:string;
begin
result:=true;
try
 if fileexists(fexec) then ffexec:=fexec else

<snip>

Dne sreda 16. novembra 2005 15:37 je Kleiton Luiz napisal(a):
Hi, i'm try to send a commad to shell...

example: i need send to shell a command "ls" and save results in a file "lists.txt"

in a shel this command make this job:

$ ls > lists.txt

i need in Lazarus execute this command.

anypeople can help me ? Thanks !

Or you can use the lazy man's method.

Include "unix" in the uses clause, then do:

 shell('ls "/my directory/" > "/destination/lists.txt"');

It won't work in Windows though, and isn't as safe as using a TProcess. If the shell command doesn't immediately return from executing, it will appear to lock up your application. Also, note the single quotes around the total command line, and the double-quotes within the command line to handle spaces within the paths.

For Windows, the shortcut is:

include "windows" in the uses clause then do:

shellexecute(0, 'open', pchar('dir "c:\my directory" > "c:\destination\lists.txt"'), nil, nil, SW_SHOWNORMAL);

I just give these as examples. I recommend the TProcess method, because it's cross-platform and has more checks and balances built in. But, I admit that when I'm spitting out a quick program just for myself, I'm more likely to use "shell()"

-Tony

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to