Execute a system command: Difference between revisions

no edit summary
(→‎{{header|Objective-C}}: added complete example (because of NSAutoreleasePool I believe it is needed))
No edit summary
Line 1:
{{Task|Programming environment operations}}
 
In this task, the goal is to run either the <codett>ls</codett> (<codett>dir</codett> on Windows) system command, or the <codett>pause</codett> system command.
 
=={{header|Ada}}==
Line 112:
=={{header|Java}}==
{{works with|Java|1.5+}}
<lang java>import java.util.Scanner;
import java.io.*;
 
Line 126:
}
}
}</javalang>
 
{{works with|Java|1.4+}}
Line 281:
<!-- {{libheader|Cocoa}} -->
 
<lang objc>#import <Cocoa/Cocoa.h>
//works also with
//#import <Foundation/Foundation.h>
Line 302:
[pool release];
return 0;
}</objclang>
 
 
Line 310:
Just run the command:
 
<lang ocaml>Sys.command "ls"</ocamllang>
 
To capture the output of the command:
 
<lang ocaml>#load "unix.cma";;
let syscall cmd =
let inc, outc = Unix.open_process cmd in
Line 325:
let _status = Unix.close_process (inc, outc) in
Buffer.contents buf;;
let listing = syscall "ls";;</ocamllang>
 
=={{header|Perl}}==