This commit is contained in:
Ingy döt Net 2013-04-10 16:57:12 -07:00
parent 518da4a923
commit 764da6cbbb
6144 changed files with 83610 additions and 11 deletions

View file

@ -0,0 +1 @@
In this task, the goal is to run either the <tt>ls</tt> (<tt>dir</tt> on Windows) system command, or the <tt>pause</tt> system command.

View file

@ -0,0 +1,2 @@
---
note: Programming environment operations

View file

@ -0,0 +1 @@
system("ls")

View file

@ -0,0 +1,5 @@
OP ! = (STRING cmd)BOOL: system(cmd) = 0;
IF ! "touch test.tmp" ANDF ( ! "ls test.tmp" ANDF ! "rm test.tmp" ) THEN
print (("test.tmp now gone!", new line))
FI

View file

@ -0,0 +1,3 @@
BEGIN {
system("ls")
}

View file

@ -0,0 +1,8 @@
with POSIX.Unsafe_Process_Primitives;
procedure Execute_A_System_Command is
Arguments : POSIX.POSIX_String_List;
begin
POSIX.Append (Arguments, "ls");
POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;

View file

@ -0,0 +1,9 @@
with Interfaces.C; use Interfaces.C;
procedure Execute_System is
function Sys (Arg : Char_Array) return Integer;
pragma Import(C, Sys, "system");
Ret_Val : Integer;
begin
Ret_Val := Sys(To_C("ls"));
end Execute_System;

View file

@ -0,0 +1,20 @@
with Ada.Text_IO; use Ada.Text_IO;
with System.OS_Lib; use System.OS_Lib;
procedure Execute_Synchronously is
Result : Integer;
Arguments : Argument_List :=
( 1=> new String'("cmd.exe"),
2=> new String'("/C dir c:\temp\*.adb")
);
begin
Spawn
( Program_Name => "cmd.exe",
Args => Arguments,
Output_File_Descriptor => Standout,
Return_Code => Result
);
for Index in Arguments'Range loop
Free (Arguments (Index)); -- Free the argument list
end loop;
end Execute_Synchronously;

View file

@ -0,0 +1,4 @@
var lines = system ("ls")
foreach line lines {
println (line)
}

View file

@ -0,0 +1 @@
exec ("ls")

View file

@ -0,0 +1,8 @@
var pid = fork()
if (pid == 0) {
var args = ["/bin/ls"]
execv ("/bin/ls", args)
exit(1)
}
var status = 0
waitpid (pid, status)

View file

@ -0,0 +1,7 @@
sshell ss;
b_cast(ss_path(ss), "/bin/ls");
lf_p_text(ss_argv(ss), "ls");
o_text(ss_link(ss));

View file

@ -0,0 +1 @@
do shell script "ls" without altering line endings

View file

@ -0,0 +1 @@
Run, %comspec% /k dir & pause

View file

@ -0,0 +1 @@
SHELL "dir"

View file

@ -0,0 +1 @@
OSCLI "CAT"

View file

@ -0,0 +1 @@
OSCLI "*dir":REM *dir to bypass BB4W's built-in dir command

View file

@ -0,0 +1 @@
OSCLI "ls"

View file

@ -0,0 +1 @@
sys$dir

View file

@ -0,0 +1,3 @@
include :subprocess
p subprocess.run :ls #Lists files in directory

View file

@ -0,0 +1 @@
exec ls

View file

@ -0,0 +1 @@
system("pause");

View file

@ -0,0 +1,7 @@
#include <stdlib.h>
int main()
{
system("ls");
return 0;
}

View file

@ -0,0 +1 @@
execute_process(COMMAND ls)

View file

@ -0,0 +1,7 @@
# Calculate pi to 40 digits after the decimal point.
execute_process(
COMMAND printf "scale = 45; 4 * a(1) + 5 / 10 ^ 41\\n"
COMMAND bc -l
COMMAND sed -e "s/.\\{5\\}$//"
OUTPUT_VARIABLE pi OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "pi is ${pi}")

View file

@ -0,0 +1 @@
(.. Runtime getRuntime (exec "cmd /C dir"))

View file

@ -0,0 +1,18 @@
user=> (use '[clojure.java.shell :only [sh]])
user=> (sh "ls" "-aul")
{:exit 0,
:out total 64
drwxr-xr-x 11 zkim staff 374 Jul 5 13:21 .
drwxr-xr-x 25 zkim staff 850 Jul 5 13:02 ..
drwxr-xr-x 12 zkim staff 408 Jul 5 13:02 .git
-rw-r--r-- 1 zkim staff 13 Jul 5 13:02 .gitignore
-rw-r--r-- 1 zkim staff 12638 Jul 5 13:02 LICENSE.html
-rw-r--r-- 1 zkim staff 4092 Jul 5 13:02 README.md
drwxr-xr-x 2 zkim staff 68 Jul 5 13:15 classes
drwxr-xr-x 5 zkim staff 170 Jul 5 13:15 lib
-rw-r--r--@ 1 zkim staff 3396 Jul 5 13:03 pom.xml
-rw-r--r--@ 1 zkim staff 367 Jul 5 13:15 project.clj
drwxr-xr-x 4 zkim staff 136 Jul 5 13:15 src
, :err }

View file

@ -0,0 +1,14 @@
user=> (use '[clojure.java.shell :only [sh]])
user=> (println (:out (sh "cowsay" "Printing a command-line output")))
_________________________________
< Printing a command-line output. >
---------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
nil

View file

@ -0,0 +1 @@
(with-output-to-string (stream) (extensions:run-program "ls" nil :output stream))

View file

@ -0,0 +1 @@
(system:call-system "ls")

View file

@ -0,0 +1 @@
(trivial-shell:shell-command "ls")

View file

@ -0,0 +1 @@
std.process.system("ls");

View file

@ -0,0 +1 @@
Directory

View file

@ -0,0 +1 @@
dir

View file

@ -0,0 +1,9 @@
program ExecuteSystemCommand;
{$APPTYPE CONSOLE}
uses Windows, ShellApi;
begin
ShellExecute(0, nil, 'cmd.exe', ' /c dir', nil, SW_HIDE);
end.

View file

@ -0,0 +1,10 @@
def ls := makeCommand("ls")
ls("-l")
def [results, _, _] := ls.exec(["-l"])
when (results) -> {
def [exitCode, out, err] := results
print(out)
} catch problem {
print(`failed to execute ls: $problem`)
}

View file

@ -0,0 +1 @@
os:cmd("ls").

View file

@ -0,0 +1 @@
s" ls" system

View file

@ -0,0 +1,3 @@
program SystemTest
call system("ls")
end program SystemTest

View file

@ -0,0 +1,13 @@
package main
import "fmt"
import "os/exec"
func main() {
cmd := exec.Command("ls", "-l")
output, err := cmd.Output()
if (err != nil) {
fmt.Println(err)
return
}
fmt.Print(string(output))
}

View file

@ -0,0 +1,3 @@
import System.Cmd
main = system "ls"

View file

@ -0,0 +1,15 @@
import java.util.Scanner;
import java.io.*;
public class Program {
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("cmd /C dir");//Windows command, use "ls -oa" for UNIX
Scanner sc = new Scanner(p.getInputStream());
while (sc.hasNext()) System.out.println(sc.nextLine());
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}
}

View file

@ -0,0 +1,39 @@
import java.io.IOException;
import java.io.InputStream;
public class MainEntry {
public static void main(String[] args) {
executeCmd("ls -oa");
}
private static void executeCmd(String string) {
InputStream pipedOut = null;
try {
Process aProcess = Runtime.getRuntime().exec(string);
aProcess.waitFor();
pipedOut = aProcess.getInputStream();
byte buffer[] = new byte[2048];
int read = pipedOut.read(buffer);
// Replace following code with your intends processing tools
while(read >= 0) {
System.out.write(buffer, 0, read);
read = pipedOut.read(buffer);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
} finally {
if(pipedOut != null) {
try {
pipedOut.close();
} catch (IOException e) {
}
}
}
}
}

View file

@ -0,0 +1,64 @@
import java.io.IOException;
import java.io.InputStream;
public class MainEntry {
public static void main(String[] args) {
// the command to execute
executeCmd("ls -oa");
}
private static void executeCmd(String string) {
InputStream pipedOut = null;
try {
Process aProcess = Runtime.getRuntime().exec(string);
// These two thread shall stop by themself when the process end
Thread pipeThread = new Thread(new StreamGobber(aProcess.getInputStream()));
Thread errorThread = new Thread(new StreamGobber(aProcess.getErrorStream()));
pipeThread.start();
errorThread.start();
aProcess.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}
//Replace the following thread with your intends reader
class StreamGobber implements Runnable {
private InputStream Pipe;
public StreamGobber(InputStream pipe) {
if(pipe == null) {
throw new NullPointerException("bad pipe");
}
Pipe = pipe;
}
public void run() {
try {
byte buffer[] = new byte[2048];
int read = Pipe.read(buffer);
while(read >= 0) {
System.out.write(buffer, 0, read);
read = Pipe.read(buffer);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(Pipe != null) {
try {
Pipe.close();
} catch (IOException e) {
}
}
}
}
}

View file

@ -0,0 +1,2 @@
var shell = new ActiveXObject("WScript.Shell");
shell.run("cmd /c dir & pause");

View file

@ -0,0 +1,10 @@
runCommand("cmd", "/c", "dir", "d:\\");
print("===");
var options = {
// can specify arguments here in the options object
args: ["/c", "dir", "d:\\"],
// capture stdout to the options.output property
output: ''
};
runCommand("cmd", options);
print(options.output);

View file

@ -0,0 +1,6 @@
-- just executing the command
os.execute("ls")
-- to execute and capture the output, use io.popen
local f = io.popen("ls") -- store the output in a "file"
print( f:read("*a") ) -- print out the "file"'s content

View file

@ -0,0 +1,8 @@
>> system('PAUSE')
Press any key to continue . . .
ans =
0

View file

@ -0,0 +1,2 @@
@exec($command,$output);
echo nl2br($output);

View file

@ -0,0 +1,11 @@
$results = `ls`;
# runs command and returns its STDOUT as a string
system("ls");
# runs command and returns its exit status; its STDOUT gets output to our STDOUT
echo `ls`;
# the same, but with back quotes
passthru("ls");
# like system() but binary-safe

View file

@ -0,0 +1,13 @@
my @results = qx(ls);
# runs command and returns its STDOUT as a string
my @results = `ls`;
# ditto, alternative syntax
system "ls";
# runs command and returns its exit status; its STDOUT gets output to our STDOUT
print `ls`;
#The same, but with back quotes
exec "ls";
# replace current process with another

View file

@ -0,0 +1 @@
(call "ls")

View file

@ -0,0 +1 @@
shell('ls').

View file

@ -0,0 +1,3 @@
import os
exit_code = os.system('ls') # Just execute the command, return a success/fail code
output = os.popen('ls').read() # If you want to get the output data. Deprecated.

View file

@ -0,0 +1,5 @@
import subprocess
# if the exit code was non-zero these commands raise a CalledProcessError
exit_code = subprocess.check_call(['ls', '-l']) # Python 2.5+
assert exit_code == 0
output = subprocess.check_output(['ls', '-l']) # Python 2.7+

View file

@ -0,0 +1,3 @@
from subprocess import PIPE, Popen, STDOUT
p = Popen('ls', stdout=PIPE, stderr=STDOUT)
print p.communicate()[0]

View file

@ -0,0 +1,4 @@
import commands
stat, out = commands.getstatusoutput('ls')
if not stat:
print out

View file

@ -0,0 +1,2 @@
system("ls")
output=system("ls",intern=TRUE)

View file

@ -0,0 +1 @@
"dir /a:d"

View file

@ -0,0 +1,18 @@
string = `ls`
# runs command and returns its STDOUT as a string
string = %x{ls}
# ditto, alternative syntax
system "ls"
# runs command and returns its exit status; its STDOUT gets output to our STDOUT
print `ls`
#The same, but with back quotes
exec "ls"
# replace current process with another
# call system command and read output asynchronously
io = IO.popen('ls')
# ... later
io.each {|line| puts line}

View file

@ -0,0 +1,2 @@
import scala.sys.process.Process
Process("ls", Seq("-oa"))!

View file

@ -0,0 +1 @@
(system "ls")

View file

@ -0,0 +1 @@
Smalltalk system: 'ls'.

View file

@ -0,0 +1 @@
puts [exec ls]

View file

@ -0,0 +1 @@
set io [open "|ls" r]

View file

@ -0,0 +1 @@
set nextline [gets $io]

View file

@ -0,0 +1 @@
set lsoutput [read $io]