Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Execute_a_system_command
note: Programming environment operations

View file

@ -0,0 +1,7 @@
;Task:
Run either the &nbsp; <tt>'''ls'''</tt> &nbsp; system command &nbsp; (<tt>'''dir'''</tt> &nbsp; on Windows), &nbsp; or the &nbsp; <tt>'''pause'''</tt> &nbsp; system command.
<br><br>
;Related task
* [[Get_system_command_output | Get system command output]]
<br><br>

View file

@ -0,0 +1 @@
os:(pause)

View 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.

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,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

View file

@ -0,0 +1,4 @@
BEGIN {
system("ls") # Unix
#system("dir") # DOS/MS-Windows
}

View file

@ -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
}

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,5 @@
sshell ss;
ss.argv.insert("ls");
o_(ss.link);

View file

@ -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

View file

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

View file

@ -0,0 +1 @@
? CHR$(4)"CATALOG"

View file

@ -0,0 +1 @@
print execute "ls"

View file

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

View file

@ -0,0 +1 @@
Run(@ComSpec & " /c " & 'pause', "", @SW_HIDE)

View file

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

View file

@ -0,0 +1 @@
system "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 @@
•SH "ls"

View file

@ -0,0 +1,2 @@
' Execute a system command
SYSTEM "ls"

View file

@ -0,0 +1 @@
"sl"=@;pushes ls, = executes it, @ ends it;

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,2 @@
ls # run command, return to shell
exec ls # replace shell with command

View file

@ -0,0 +1,3 @@
set output=( "`grep 80/ /etc/services`" )
echo "Line 1: $output[1]"
echo "Line 2: $output[2]"

View file

@ -0,0 +1,12 @@
using System.Diagnostics;
namespace Execute
{
class Program
{
static void Main(string[] args)
{
Process.Start("cmd.exe", "/c dir");
}
}
}

View file

@ -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();
}
}

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 @@
CALL "SYSTEM" USING BY CONTENT "ls"

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,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."

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,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*)

View file

@ -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

View file

@ -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

View file

@ -0,0 +1 @@
Directory

View file

@ -0,0 +1 @@
dir

View file

@ -0,0 +1 @@
! ls

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 @@
SHELL("DIR/W")

View file

@ -0,0 +1,2 @@
cmd$="DIR/W"
SHELL(cmd$)

View file

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

View file

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

View file

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

View file

@ -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

View file

@ -0,0 +1 @@
System.Diagnostics.Process.Start("cmd", "/c dir")

View file

@ -0,0 +1 @@
"ls" run-process wait-for-process

View file

@ -0,0 +1,8 @@
class Main
{
public static Void main ()
{
p := Process (["ls"])
p.run
}
}

View file

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

View file

@ -0,0 +1,4 @@
program SystemTest
integer :: i
call execute_command_line ("ls", exitstat=i)
end program SystemTest

View file

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

View file

@ -0,0 +1,4 @@
' FB 1.05.0 Win64
Shell "dir"
Sleep

View file

@ -0,0 +1,2 @@
r = callJava["java.lang.Runtime", "getRuntime"]
println[read[r.exec["dir"].getInputStream[]]]

View file

@ -0,0 +1,3 @@
import sys.execute
execute( if $os.startsWith('Windows') then 'dir' else 'ls' )

View file

@ -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" )

View file

@ -0,0 +1 @@
Start,Programs,Accessories,MSDOS Prompt,Type:dir[enter]

View file

@ -0,0 +1,5 @@
Public Sub Main()
Shell "ls -aul"
End

View file

@ -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)

View 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)
}
}

View file

@ -0,0 +1 @@
println "ls -la".execute().text

View file

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

View file

@ -0,0 +1,2 @@
SYSTEM(CoMmand='pause')
SYSTEM(CoMmand='dir & pause')

View file

@ -0,0 +1 @@
Dir;

View file

@ -0,0 +1 @@
$ls

View file

@ -0,0 +1 @@
spawn,"ls",result

View file

@ -0,0 +1 @@
spawn,"ls",unit=unit

View file

@ -0,0 +1 @@
100 EXT "dir"

View file

@ -0,0 +1,6 @@
procedure main()
write("Trying command ",cmd := if &features == "UNIX" then "ls" else "dir")
system(cmd)
end

View file

@ -0,0 +1,2 @@
pid := system(command_string,&input,&output,&errout,"wait")
pid := system(command_string,&input,&output,&errout,"nowait")

View file

@ -0,0 +1 @@
System runCommand("ls") stdout println

View 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'

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 @@
"ls" system.

View file

@ -0,0 +1 @@
run(`ls`)

View file

@ -0,0 +1 @@
\ls

View file

@ -0,0 +1 @@
r: 4:"ls"

Some files were not shown because too many files have changed in this diff Show more