함수 shell exec()

  다른 뜻에 대해서는 PHP shell_exec() 문서를 참조하십시오.

1 Java[ | ]

Java
Copy
// String[] commands = { "bash", "-c", "echo hello" };
String[] commands = { "CMD", "/C", "echo hello" };
Process proc = Runtime.getRuntime().exec(commands);
BufferedReader brOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader brErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String line;
List<String> outLines = new ArrayList<String>();
List<String> errLines = new ArrayList<String>();
while ((line = brOut.readLine()) != null) outLines.add(line);
while ((line = brErr.readLine()) != null) errLines.add(line);
String newline = System.getProperty("line.separator");
System.out.println("stdOut: " + String.join(newline, outLines));
System.out.println("stdErr: " + String.join(newline, errLines));
// stdOut: hello
// stdErr:

2 PHP[ | ]

PHP
Copy
echo shell_exec('whoami');
# root
PHP
Copy
echo shell_exec('cat /etc/at.deny | head -3');
# alias
# backup
# bin

3 Python[ | ]

Python
Copy
import os
result = os.system('cat /etc/at.deny | head -3')
print result
# alias
# backup
# bin
# 0
Python
Copy
import os
result = os.popen('cat /etc/at.deny | head -3').read()
print result
# alias
# backup
# bin
#

4 같이 보기[ | ]