digitalmars.D.learn - very short pipeShell program
- WhatMeWorry (15/15) Jun 22 2014 After hours of reading (obviously not comprehending) std.process
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (21/33) Jun 22 2014 As I understand it, the returned 'pipe' is used to communicate with the
- John Carter (3/3) Jun 23 2014 Ali, of course, is right. The only thing I'd add is for a
After hours of reading (obviously not comprehending) std.process and looking at code samples, I still can't even do something this simple. Open a Windows command line and run miscellaneous commands. Only the first command, dir" is shown in the final output. auto pipe = pipeShell("dir", Redirect.all); pipe.stdin.writeln("cd"); pipe.stdin.writeln("whomai"); pipe.stdin.flush(); pipe.stdin.close(); foreach(str; pipe.stdout.byLine) writefln("from shell: %s",str); I tried putting the wait() command was well in various places. to no avail.
Jun 22 2014
On 06/22/2014 05:01 PM, WhatMeWorry wrote:After hours of reading (obviously not comprehending) std.process and looking at code samples, I still can't even do something this simple. Open a Windows command line and run miscellaneous commands. Only the first command, dir" is shown in the final output. auto pipe = pipeShell("dir", Redirect.all); pipe.stdin.writeln("cd"); pipe.stdin.writeln("whomai");Typo: whoamipipe.stdin.flush(); pipe.stdin.close(); foreach(str; pipe.stdout.byLine) writefln("from shell: %s",str); I tried putting the wait() command was well in various places. to no avail.As I understand it, the returned 'pipe' is used to communicate with the command passed to pipeShell. Since 'dir' does not understand 'cd', 'whoami', etc. it fails for you. I tried the following on Linux and it worked. I think you must replace "bash" with "cmd" on Windows: import std.stdio; import std.process; void main() { auto pipe = pipeShell("bash", Redirect.all); pipe.stdin.writeln("dir"); pipe.stdin.writeln("cd"); pipe.stdin.writeln("whoami"); pipe.stdin.flush(); pipe.stdin.close(); foreach(str; pipe.stdout.byLine) writefln("from shell: %s",str); } Ali
Jun 22 2014
Ali, of course, is right. The only thing I'd add is for a Windowsy programmer (unless you have cygwin installed) you probably want something like "cmd.exe" instead of bash.
Jun 23 2014