Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Execute-a-system-command/00-META.yaml
Normal file
3
Task/Execute-a-system-command/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Execute_a_system_command
|
||||
note: Programming environment operations
|
||||
7
Task/Execute-a-system-command/00-TASK.txt
Normal file
7
Task/Execute-a-system-command/00-TASK.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
;Task:
|
||||
Run either the <tt>'''ls'''</tt> system command (<tt>'''dir'''</tt> on Windows), or the <tt>'''pause'''</tt> system command.
|
||||
<br><br>
|
||||
;Related task
|
||||
* [[Get_system_command_output | Get system command output]]
|
||||
<br><br>
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
os:(‘pause’)
|
||||
134
Task/Execute-a-system-command/ABAP/execute-a-system-command.abap
Normal file
134
Task/Execute-a-system-command/ABAP/execute-a-system-command.abap
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
*&---------------------------------------------------------------------*
|
||||
*& Report ZEXEC_SYS_CMD
|
||||
*&
|
||||
*&---------------------------------------------------------------------*
|
||||
*&
|
||||
*&
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
REPORT zexec_sys_cmd.
|
||||
|
||||
DATA: lv_opsys TYPE syst-opsys,
|
||||
lt_sxpgcotabe TYPE TABLE OF sxpgcotabe,
|
||||
ls_sxpgcotabe LIKE LINE OF lt_sxpgcotabe,
|
||||
ls_sxpgcolist TYPE sxpgcolist,
|
||||
lv_name TYPE sxpgcotabe-name,
|
||||
lv_opcommand TYPE sxpgcotabe-opcommand,
|
||||
lv_index TYPE c,
|
||||
lt_btcxpm TYPE TABLE OF btcxpm,
|
||||
ls_btcxpm LIKE LINE OF lt_btcxpm
|
||||
.
|
||||
|
||||
* Initialize
|
||||
lv_opsys = sy-opsys.
|
||||
CLEAR lt_sxpgcotabe[].
|
||||
|
||||
IF lv_opsys EQ 'Windows NT'.
|
||||
lv_opcommand = 'dir'.
|
||||
ELSE.
|
||||
lv_opcommand = 'ls'.
|
||||
ENDIF.
|
||||
|
||||
* Check commands
|
||||
SELECT * FROM sxpgcotabe INTO TABLE lt_sxpgcotabe
|
||||
WHERE opsystem EQ lv_opsys
|
||||
AND opcommand EQ lv_opcommand.
|
||||
|
||||
IF lt_sxpgcotabe IS INITIAL.
|
||||
CLEAR ls_sxpgcolist.
|
||||
CLEAR lv_name.
|
||||
WHILE lv_name IS INITIAL.
|
||||
* Don't mess with other users' commands
|
||||
lv_index = sy-index.
|
||||
CONCATENATE 'ZLS' lv_index INTO lv_name.
|
||||
SELECT * FROM sxpgcostab INTO ls_sxpgcotabe
|
||||
WHERE name EQ lv_name.
|
||||
ENDSELECT.
|
||||
IF sy-subrc = 0.
|
||||
CLEAR lv_name.
|
||||
ENDIF.
|
||||
ENDWHILE.
|
||||
ls_sxpgcolist-name = lv_name.
|
||||
ls_sxpgcolist-opsystem = lv_opsys.
|
||||
ls_sxpgcolist-opcommand = lv_opcommand.
|
||||
* Create own ls command when nothing is declared
|
||||
CALL FUNCTION 'SXPG_COMMAND_INSERT'
|
||||
EXPORTING
|
||||
command = ls_sxpgcolist
|
||||
public = 'X'
|
||||
EXCEPTIONS
|
||||
command_already_exists = 1
|
||||
no_permission = 2
|
||||
parameters_wrong = 3
|
||||
foreign_lock = 4
|
||||
system_failure = 5
|
||||
OTHERS = 6.
|
||||
IF sy-subrc <> 0.
|
||||
* Implement suitable error handling here
|
||||
ELSE.
|
||||
* Hooray it worked! Let's try to call it
|
||||
CALL FUNCTION 'SXPG_COMMAND_EXECUTE_LONG'
|
||||
EXPORTING
|
||||
commandname = lv_name
|
||||
TABLES
|
||||
exec_protocol = lt_btcxpm
|
||||
EXCEPTIONS
|
||||
no_permission = 1
|
||||
command_not_found = 2
|
||||
parameters_too_long = 3
|
||||
security_risk = 4
|
||||
wrong_check_call_interface = 5
|
||||
program_start_error = 6
|
||||
program_termination_error = 7
|
||||
x_error = 8
|
||||
parameter_expected = 9
|
||||
too_many_parameters = 10
|
||||
illegal_command = 11
|
||||
wrong_asynchronous_parameters = 12
|
||||
cant_enq_tbtco_entry = 13
|
||||
jobcount_generation_error = 14
|
||||
OTHERS = 15.
|
||||
IF sy-subrc <> 0.
|
||||
* Implement suitable error handling here
|
||||
WRITE: 'Cant execute ls - '.
|
||||
CASE sy-subrc.
|
||||
WHEN 1.
|
||||
WRITE: / ' no permission!'.
|
||||
WHEN 2.
|
||||
WRITE: / ' command could not be created!'.
|
||||
WHEN 3.
|
||||
WRITE: / ' parameter list too long!'.
|
||||
WHEN 4.
|
||||
WRITE: / ' security risk!'.
|
||||
WHEN 5.
|
||||
WRITE: / ' wrong call of SXPG_COMMAND_EXECUTE_LONG!'.
|
||||
WHEN 6.
|
||||
WRITE: / ' command cant be started!'.
|
||||
WHEN 7.
|
||||
WRITE: / ' program terminated!'.
|
||||
WHEN 8.
|
||||
WRITE: / ' x_error!'.
|
||||
WHEN 9.
|
||||
WRITE: / ' parameter missing!'.
|
||||
WHEN 10.
|
||||
WRITE: / ' too many parameters!'.
|
||||
WHEN 11.
|
||||
WRITE: / ' illegal command!'.
|
||||
WHEN 12.
|
||||
WRITE: / ' wrong asynchronous parameters!'.
|
||||
WHEN 13.
|
||||
WRITE: / ' cant enqueue job!'.
|
||||
WHEN 14.
|
||||
WRITE: / ' cant create job!'.
|
||||
WHEN 15.
|
||||
WRITE: / ' unknown error!'.
|
||||
WHEN OTHERS.
|
||||
WRITE: / ' unknown error!'.
|
||||
ENDCASE.
|
||||
ELSE.
|
||||
LOOP AT lt_btcxpm INTO ls_btcxpm.
|
||||
WRITE: / ls_btcxpm.
|
||||
ENDLOOP.
|
||||
ENDIF.
|
||||
ENDIF.
|
||||
ENDIF.
|
||||
|
|
@ -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,11 @@
|
|||
∇ system s;handle
|
||||
⍝⍝ NOTE: one MUST give the full absolute path to the program (eg. /bin/ls)
|
||||
⍝⍝ Exercise: Can you improve this by parsing the value of
|
||||
⍝⍝ ⎕ENV 'PATH' ?
|
||||
⍝⍝
|
||||
handle ← ⎕fio['fork_daemon'] s
|
||||
⎕fio['fclose'] handle
|
||||
∇
|
||||
system '/bin/ls /var'
|
||||
backups games lib lock mail run tmp
|
||||
cache gemini local log opt spool
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
BEGIN {
|
||||
system("ls") # Unix
|
||||
#system("dir") # DOS/MS-Windows
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
BEGIN {
|
||||
ls = sys2var("ls")
|
||||
print ls
|
||||
}
|
||||
function sys2var(command ,fish, scale, ship) {
|
||||
command = command " 2>/dev/null"
|
||||
while ( (command | getline fish) > 0 ) {
|
||||
if ( ++scale == 1 )
|
||||
ship = fish
|
||||
else
|
||||
ship = ship "\n" fish
|
||||
}
|
||||
close(command)
|
||||
return ship
|
||||
}
|
||||
|
|
@ -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,5 @@
|
|||
sshell ss;
|
||||
|
||||
ss.argv.insert("ls");
|
||||
|
||||
o_(ss.link);
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/hopper
|
||||
|
||||
#include <hopper.h>
|
||||
|
||||
main:
|
||||
|
||||
/* execute "ls -lstar" with no result return (only displayed) */
|
||||
{"ls -lstar"},execv
|
||||
|
||||
/* this form does not allow composition of the line with variables.
|
||||
Save result in the variable "s", and then display it */
|
||||
s=`ls -l | awk '{if($2=="2")print $0;}'`
|
||||
{"\n",s,"\n"}print
|
||||
|
||||
data="2"
|
||||
{""}tok sep
|
||||
|
||||
// the same as above, only I can compose the line:
|
||||
{"ls -l | awk '{if($2==\"",data,"\")print $0;}'"}join(s),{s}exec,print
|
||||
{"\n\n"}print
|
||||
|
||||
// this does the same as above, with an "execute" macro inside a "let" macro:
|
||||
t=0,let (t := execute( {"ls -l | awk '{if($2==\""},{data},{"\")print $0;}'"} ))
|
||||
{t,"\n"}print
|
||||
|
||||
{0}return
|
||||
|
|
@ -0,0 +1 @@
|
|||
do shell script "ls" without altering line endings
|
||||
|
|
@ -0,0 +1 @@
|
|||
? CHR$(4)"CATALOG"
|
||||
|
|
@ -0,0 +1 @@
|
|||
print execute "ls"
|
||||
|
|
@ -0,0 +1 @@
|
|||
Run, %comspec% /k dir & pause
|
||||
|
|
@ -0,0 +1 @@
|
|||
Run(@ComSpec & " /c " & 'pause', "", @SW_HIDE)
|
||||
|
|
@ -0,0 +1 @@
|
|||
SHELL "dir"
|
||||
|
|
@ -0,0 +1 @@
|
|||
system "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 @@
|
|||
•SH ⟨"ls"⟩
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
' Execute a system command
|
||||
SYSTEM "ls"
|
||||
|
|
@ -0,0 +1 @@
|
|||
dir
|
||||
|
|
@ -0,0 +1 @@
|
|||
"sl"=@;pushes ls, = executes it, @ ends it;
|
||||
|
|
@ -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,2 @@
|
|||
ls # run command, return to shell
|
||||
exec ls # replace shell with command
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
set output=( "`grep 80/ /etc/services`" )
|
||||
echo "Line 1: $output[1]"
|
||||
echo "Line 2: $output[2]"
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Process.Start("cmd.exe", "/c dir");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
|
||||
class Execute {
|
||||
static void Main() {
|
||||
System.Diagnostics.Process proc = new System.Diagnostics.Process();
|
||||
proc.EnableRaisingEvents=false;
|
||||
proc.StartInfo.FileName="ls";
|
||||
proc.Start();
|
||||
}
|
||||
}
|
||||
|
|
@ -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 @@
|
|||
CALL "SYSTEM" USING BY CONTENT "ls"
|
||||
|
|
@ -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,9 @@
|
|||
{ spawn } = require 'child_process'
|
||||
|
||||
ls = spawn 'ls'
|
||||
|
||||
ls.stdout.on 'data', ( data ) -> console.log "Output: #{ data }"
|
||||
|
||||
ls.stderr.on 'data', ( data ) -> console.error "Error: #{ data }"
|
||||
|
||||
ls.on 'close', -> console.log "'ls' has finished executing."
|
||||
|
|
@ -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,8 @@
|
|||
; uiop is part of the de facto build system, asdf, so should be available to most installations.
|
||||
|
||||
; synchronous
|
||||
(uiop:run-program "ls")
|
||||
|
||||
; async
|
||||
(defparameter *process* (uiop:launch-program "ls"))
|
||||
(uiop:wait-process *process*)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import std.process, std.stdio;
|
||||
//these two alternatives wait for the process to return, and capture the output
|
||||
//each process function returns a Tuple of (int)"status" and (string)"output
|
||||
auto ls_string = executeShell("ls -l"); //takes single string
|
||||
writeln((ls_string.status == 0) ? ls_string.output : "command failed");
|
||||
|
||||
auto ls_array = execute(["ls", "-l"]); //takes array of strings
|
||||
writeln((ls_array.status == 0) ? ls_array.output : "command failed");
|
||||
//other alternatives exist to spawn processes in parallel and capture output via pipes
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
XCALL SPAWN ("ls *.jpg > file.txt") ;execute command and continue
|
||||
XCALL EXEC ("script.sh") ;execute script or binary and exit
|
||||
STOP '@/bin/ls *.jpg > file.txt' ;exit and execute command
|
||||
|
|
@ -0,0 +1 @@
|
|||
Directory
|
||||
|
|
@ -0,0 +1 @@
|
|||
dir
|
||||
|
|
@ -0,0 +1 @@
|
|||
! ls
|
||||
|
|
@ -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 @@
|
|||
SHELL("DIR/W")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
cmd$="DIR/W"
|
||||
SHELL(cmd$)
|
||||
|
|
@ -0,0 +1 @@
|
|||
(shell-command "ls")
|
||||
|
|
@ -0,0 +1 @@
|
|||
(async-shell-command "ls")
|
||||
|
|
@ -0,0 +1 @@
|
|||
os:cmd("ls").
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
-- system --
|
||||
-- the simplest way --
|
||||
-- system spawns a new shell so I/O redirection is possible --
|
||||
|
||||
system( "dir /w c:\temp\ " ) -- Microsoft --
|
||||
|
||||
system( "/bin/ls -l /tmp" ) -- Linux BSD OSX --
|
||||
|
||||
----
|
||||
|
||||
-- system_exec() --
|
||||
-- system_exec does not spawn a new shell --
|
||||
-- ( like bash or cmd.exe ) --
|
||||
|
||||
integer exit_code = 0
|
||||
sequence ls_command = ""
|
||||
|
||||
ifdef UNIX or LINUX or OSX then
|
||||
ls_command = "/bin/ls -l "
|
||||
elsifdef WINDOWS then
|
||||
ls_command = "dir /w "
|
||||
end ifdef
|
||||
|
||||
exit_code = system_exec( ls_command )
|
||||
|
||||
if exit_code = -1 then
|
||||
puts( STDERR, " could not execute " & ls_command & "\n" )
|
||||
elsif exit_code = 0 then
|
||||
puts( STDERR, ls_command & " succeeded\n")
|
||||
else
|
||||
printf( STDERR, "command %s failed with code %d\n", ls_command, exit_code)
|
||||
end if
|
||||
|
|
@ -0,0 +1 @@
|
|||
System.Diagnostics.Process.Start("cmd", "/c dir")
|
||||
|
|
@ -0,0 +1 @@
|
|||
"ls" run-process wait-for-process
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
p := Process (["ls"])
|
||||
p.run
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
s" ls" system
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
program SystemTest
|
||||
integer :: i
|
||||
call execute_command_line ("ls", exitstat=i)
|
||||
end program SystemTest
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
program SystemTest
|
||||
call system("ls")
|
||||
end program SystemTest
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Shell "dir"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
r = callJava["java.lang.Runtime", "getRuntime"]
|
||||
println[read[r.exec["dir"].getInputStream[]]]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import sys.execute
|
||||
|
||||
execute( if $os.startsWith('Windows') then 'dir' else 'ls' )
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
local fn DoUnixCommand( cmd as str255 )
|
||||
dim as str255 s
|
||||
|
||||
open "Unix", 2, cmd
|
||||
while ( not eof(2) )
|
||||
line input #2, s
|
||||
print s
|
||||
wend
|
||||
close 2
|
||||
end fn
|
||||
|
||||
fn DoUnixCommand( "ls -A" )
|
||||
|
|
@ -0,0 +1 @@
|
|||
Start,Programs,Accessories,MSDOS Prompt,Type:dir[enter]
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Public Sub Main()
|
||||
|
||||
Shell "ls -aul"
|
||||
|
||||
End
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
[indent=4]
|
||||
/*
|
||||
Execute system command, in Genie
|
||||
|
||||
valac executeSystemCommand.gs
|
||||
./executeSystemCommand
|
||||
*/
|
||||
|
||||
init
|
||||
try
|
||||
// Non Blocking
|
||||
Process.spawn_command_line_async("ls")
|
||||
except e : SpawnError
|
||||
stderr.printf("%s\n", e.message)
|
||||
|
|
@ -0,0 +1 @@
|
|||
!ls
|
||||
16
Task/Execute-a-system-command/Go/execute-a-system-command.go
Normal file
16
Task/Execute-a-system-command/Go/execute-a-system-command.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd := exec.Command("ls", "-l")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
println "ls -la".execute().text
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import System.Cmd
|
||||
|
||||
main = system "ls"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
SYSTEM(CoMmand='pause')
|
||||
SYSTEM(CoMmand='dir & pause')
|
||||
|
|
@ -0,0 +1 @@
|
|||
Dir;
|
||||
|
|
@ -0,0 +1 @@
|
|||
$ls
|
||||
|
|
@ -0,0 +1 @@
|
|||
spawn,"ls",result
|
||||
|
|
@ -0,0 +1 @@
|
|||
spawn,"ls",unit=unit
|
||||
|
|
@ -0,0 +1 @@
|
|||
100 EXT "dir"
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
procedure main()
|
||||
|
||||
write("Trying command ",cmd := if &features == "UNIX" then "ls" else "dir")
|
||||
system(cmd)
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
pid := system(command_string,&input,&output,&errout,"wait")
|
||||
pid := system(command_string,&input,&output,&errout,"nowait")
|
||||
|
|
@ -0,0 +1 @@
|
|||
System runCommand("ls") stdout println
|
||||
15
Task/Execute-a-system-command/J/execute-a-system-command.j
Normal file
15
Task/Execute-a-system-command/J/execute-a-system-command.j
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
load'task'
|
||||
|
||||
NB. Execute a command and wait for it to complete
|
||||
shell 'dir'
|
||||
|
||||
NB. Execute a command but don't wait for it to complete
|
||||
fork 'notepad'
|
||||
|
||||
NB. Execute a command and capture its stdout
|
||||
stdout =: shell 'dir'
|
||||
|
||||
NB. Execute a command, provide it with stdin,
|
||||
NB. and capture its stdout
|
||||
stdin =: 'blahblahblah'
|
||||
stdout =: stdin spawn 'grep blah'
|
||||
|
|
@ -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 @@
|
|||
"ls" system.
|
||||
|
|
@ -0,0 +1 @@
|
|||
run(`ls`)
|
||||
|
|
@ -0,0 +1 @@
|
|||
\ls
|
||||
|
|
@ -0,0 +1 @@
|
|||
r: 4:"ls"
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue