如果我将cat命令保存到字符串中,然后执行它,那么我将得到一个错误。
linux# cmd="cat /data/test/test.tx* | grep toto"
linux# eval '$cmd'
cat: |: No such file or directory
cat: grep: No such file or directory
cat: toto: No such file or directory
即使是
linux# $cmd
cat: |: No such file or directory
cat: grep: No such file
如何在windows中使用Runtime.getRuntime().exec(命令)?
1.
command = "cat data.json"; // works in linux terminal
Runtime.getRuntime().exec(command) // runs in linux => Runs OK
2.
command = "type data.json"; // works in windows cmd
Runtime.getRuntime().exec(command) // runs in windows => F
我有一个运行linux命令的C++代码,我想模拟分段错误,即SIGSEGV,同时通过C++代码执行C++命令。所以我的代码是这样的
int main(){
string cmd = "some linux command that should throw seg fault";
execute_linux_comand(cmd); // Want to simulate segfault coming while executing this command
}
我应该放什么"cmd“,这样它才能将SIGSEGV发送到通过调用该函数创建的子进程?
我的TCL脚本使用TCL变量组合了一个对命令行工具的调用。我尝试过在命令行中使用exec或eval,但都不起作用。
#!/usr/bin/tclsh
set dbg 0
set iso 100
set cmd "gphoto2 --set-config-value /main/imgsettings/iso=${iso}"
if {$dbg} {puts $cmd} else {eval $cmd}
提供:
invalid command name "gphoto2"
while executing
"gphoto2 --set-config-value
我试图创建一个函数,返回输出,因为命令将写入或Linux中的命令行
示例:
def cmd_simulator(commands):
#some code
cmd_simulator("date")
- Thu Jan 28 12:18:05 EST 2016
或Windows:
cmd_simulator("date")
- The current date is: Thu 01/28/2016
- Enter the new date: (mm-dd-yy)