digitalmars.D - capturing std out
- Charles (13/13) Oct 31 2005 Is there any way to capture stdout from an exec/system call into the pro...
- zwang (5/25) Oct 31 2005 As far as I know, you have to call platform-specific API to do this in
- Regan Heath (3/22) Oct 31 2005 Yep. Here are some examples, they may even work ;)
- Georg Wrede (14/37) Oct 31 2005 For debugging or quick-and-dirty purposes one might also do something
Is there any way to capture stdout from an exec/system call into the program ? In perl I'd do this: my output = `ls`; print output; This above allows me to parse/manipulate the output of the ls command. How would I do the equiv in D ? The following executes the ls command but doesn't give me the output inside the program. import std.process; char * cmd = "/bin/ls" system(cmd); any hlp apprec, Charles
Oct 31 2005
Charles wrote:Is there any way to capture stdout from an exec/system call into the program ? In perl I'd do this: my output = `ls`; print output; This above allows me to parse/manipulate the output of the ls command. How would I do the equiv in D ? The following executes the ls command but doesn't give me the output inside the program. import std.process; char * cmd = "/bin/ls" system(cmd); any hlp apprec, CharlesAs far as I know, you have to call platform-specific API to do this in D. In Windows, related functions include CreatePipe, SetHandleInformation, CreateProcess, PeekNamedPipe, WaitForSingleObject, ReadFile, and CloseHandle.
Oct 31 2005
On Mon, 31 Oct 2005 22:14:59 +0800, zwang <nehzgnaw gmail.com> wrote:Charles wrote:Yep. Here are some examples, they may even work ;) ReganIs there any way to capture stdout from an exec/system call into the program ? In perl I'd do this: my output = `ls`; print output; This above allows me to parse/manipulate the output of the ls command. How would I do the equiv in D ? The following executes the ls command but doesn't give me the output inside the program. import std.process; char * cmd = "/bin/ls" system(cmd); any hlp apprec, CharlesAs far as I know, you have to call platform-specific API to do this in D. In Windows, related functions include CreatePipe, SetHandleInformation, CreateProcess, PeekNamedPipe, WaitForSingleObject, ReadFile, and CloseHandle.
Oct 31 2005
Regan Heath wrote:On Mon, 31 Oct 2005 22:14:59 +0800, zwang <nehzgnaw gmail.com> wrote:For debugging or quick-and-dirty purposes one might also do something like this: system("ls -l /root /home >/tmp/lsout 2>/tmp/lserr "); Whereafter you can the read the files into your program. This has the advantage of separating error and standard output from each other. For example, on my machine the files end up containing: lsout: /home: total 4 drwxr-xr-x 24 georg georg 4096 Nov 1 00:34 georg and lserr: ls: /root: Permission deniedCharles wrote:Is there any way to capture stdout from an exec/system call into the program ? In perl I'd do this: my output = `ls`; print output; This above allows me to parse/manipulate the output of the ls command. How would I do the equiv in D ? The following executes the ls command but doesn't give me the output inside the program. import std.process; char * cmd = "/bin/ls" system(cmd); any hlp apprec, CharlesCool!As far as I know, you have to call platform-specific API to do this in D. In Windows, related functions include CreatePipe, SetHandleInformation, CreateProcess, PeekNamedPipe, WaitForSingleObject, ReadFile, and CloseHandle.Yep. Here are some examples, they may even work ;)
Oct 31 2005