CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
1
Task/Execute-a-system-command/0DESCRIPTION
Normal file
1
Task/Execute-a-system-command/0DESCRIPTION
Normal 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.
|
||||
2
Task/Execute-a-system-command/1META.yaml
Normal file
2
Task/Execute-a-system-command/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Programming environment operations
|
||||
|
|
@ -0,0 +1 @@
|
|||
system("ls")
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
BEGIN {
|
||||
system("ls")
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var lines = system ("ls")
|
||||
foreach line lines {
|
||||
println (line)
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
exec ("ls")
|
||||
|
|
@ -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)
|
||||
|
|
@ -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));
|
||||
|
|
@ -0,0 +1 @@
|
|||
do shell script "ls" without altering line endings
|
||||
|
|
@ -0,0 +1 @@
|
|||
Run, %comspec% /k dir & pause
|
||||
|
|
@ -0,0 +1 @@
|
|||
SHELL "dir"
|
||||
|
|
@ -0,0 +1 @@
|
|||
OSCLI "CAT"
|
||||
|
|
@ -0,0 +1 @@
|
|||
OSCLI "*dir":REM *dir to bypass BB4W's built-in dir command
|
||||
|
|
@ -0,0 +1 @@
|
|||
OSCLI "ls"
|
||||
|
|
@ -0,0 +1 @@
|
|||
sys$dir
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
include :subprocess
|
||||
|
||||
p subprocess.run :ls #Lists files in directory
|
||||
|
|
@ -0,0 +1 @@
|
|||
exec ls
|
||||
|
|
@ -0,0 +1 @@
|
|||
system("pause");
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
system("ls");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
execute_process(COMMAND ls)
|
||||
|
|
@ -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}")
|
||||
|
|
@ -0,0 +1 @@
|
|||
(.. Runtime getRuntime (exec "cmd /C dir"))
|
||||
|
|
@ -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 }
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
(with-output-to-string (stream) (extensions:run-program "ls" nil :output stream))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(system:call-system "ls")
|
||||
|
|
@ -0,0 +1 @@
|
|||
(trivial-shell:shell-command "ls")
|
||||
|
|
@ -0,0 +1 @@
|
|||
std.process.system("ls");
|
||||
|
|
@ -0,0 +1 @@
|
|||
Directory
|
||||
|
|
@ -0,0 +1 @@
|
|||
dir
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
program ExecuteSystemCommand;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses Windows, ShellApi;
|
||||
|
||||
begin
|
||||
ShellExecute(0, nil, 'cmd.exe', ' /c dir', nil, SW_HIDE);
|
||||
end.
|
||||
10
Task/Execute-a-system-command/E/execute-a-system-command.e
Normal file
10
Task/Execute-a-system-command/E/execute-a-system-command.e
Normal 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`)
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
os:cmd("ls").
|
||||
|
|
@ -0,0 +1 @@
|
|||
s" ls" system
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
program SystemTest
|
||||
call system("ls")
|
||||
end program SystemTest
|
||||
13
Task/Execute-a-system-command/Go/execute-a-system-command.go
Normal file
13
Task/Execute-a-system-command/Go/execute-a-system-command.go
Normal 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))
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import System.Cmd
|
||||
|
||||
main = system "ls"
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
var shell = new ActiveXObject("WScript.Shell");
|
||||
shell.run("cmd /c dir & pause");
|
||||
|
|
@ -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);
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
>> system('PAUSE')
|
||||
|
||||
Press any key to continue . . .
|
||||
|
||||
|
||||
ans =
|
||||
|
||||
0
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
@exec($command,$output);
|
||||
echo nl2br($output);
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
(call "ls")
|
||||
|
|
@ -0,0 +1 @@
|
|||
shell('ls').
|
||||
|
|
@ -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.
|
||||
|
|
@ -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+
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from subprocess import PIPE, Popen, STDOUT
|
||||
p = Popen('ls', stdout=PIPE, stderr=STDOUT)
|
||||
print p.communicate()[0]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import commands
|
||||
stat, out = commands.getstatusoutput('ls')
|
||||
if not stat:
|
||||
print out
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
system("ls")
|
||||
output=system("ls",intern=TRUE)
|
||||
|
|
@ -0,0 +1 @@
|
|||
"dir /a:d"
|
||||
|
|
@ -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}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import scala.sys.process.Process
|
||||
Process("ls", Seq("-oa"))!
|
||||
|
|
@ -0,0 +1 @@
|
|||
(system "ls")
|
||||
|
|
@ -0,0 +1 @@
|
|||
Smalltalk system: 'ls'.
|
||||
|
|
@ -0,0 +1 @@
|
|||
puts [exec ls]
|
||||
|
|
@ -0,0 +1 @@
|
|||
set io [open "|ls" r]
|
||||
|
|
@ -0,0 +1 @@
|
|||
set nextline [gets $io]
|
||||
|
|
@ -0,0 +1 @@
|
|||
set lsoutput [read $io]
|
||||
Loading…
Add table
Add a link
Reference in a new issue