Execute a system command: Difference between revisions
Content added Content deleted
(→{{header|Pike}}: add example for older pike implementations) |
|||
Line 785: | Line 785: | ||
<lang pike> |
<lang pike> |
||
int main(){ |
int main(){ |
||
// Process.run was added in Pike 7.8 as a wrapper to simplify the use of Process.create_process() |
|||
// This appears to only work in Pike >= 7.8 :( |
|||
string response = Process.run("ls"); |
string response = Process.run("ls -l"); |
||
// response is now a map containing 3 fields |
// response is now a map containing 3 fields |
||
// stderr, stdout, and exitcode. We want stdout. |
// stderr, stdout, and exitcode. We want stdout. |
||
write(response["stdout"] + "\n"); |
write(response["stdout"] + "\n"); |
||
// with older versions of pike it's a bit more complicated: |
|||
Stdio.File stdout = Stdio.File(); |
|||
Process.create_process(({"ls", "-l"}), ([ "stdout" : stdout->pipe() ]) ); |
|||
write(stdout->read() + "\n"); |
|||
}</lang> |
}</lang> |
||