我跑了类似的测试自己:
$ strace -o /tmp/gnome.out -f gnome-terminal --working-directory=/var/log --tab -e "cat *.log ; echo hello"
$ grep --color=no execve /tmp/gnome.out
28561 execve("/usr/bin/gnome-terminal", ["gnome-terminal", "--working-directory=/var/log", "--tab", "-e", "cat *.log ; echo hello"], [/* 39 vars */]) = 0
28564 execve("/usr/lib/libvte9/gnome-pty-helper", ["gnome-pty-helper"], [/* 40 vars */]) = 0
28565 execve("/home/sarnold/bin/cat", ["cat", "*.log", ";", "echo", "hello"], [/* 40 vars */]) = -1 ENOENT (No such file or directory)
28565 execve("/usr/local/sbin/cat", ["cat", "*.log", ";", "echo", "hello"], [/* 40 vars */]) = -1 ENOENT (No such file or directory)
28565 execve("/usr/local/bin/cat", ["cat", "*.log", ";", "echo", "hello"], [/* 40 vars */]) = -1 ENOENT (No such file or directory)
28565 execve("/usr/sbin/cat", ["cat", "*.log", ";", "echo", "hello"], [/* 40 vars */]) = -1 ENOENT (No such file or directory)
28565 execve("/usr/bin/cat", ["cat", "*.log", ";", "echo", "hello"], [/* 40 vars */]) = -1 ENOENT (No such file or directory)
28565 execve("/sbin/cat", ["cat", "*.log", ";", "echo", "hello"], [/* 40 vars */]) = -1 ENOENT (No such file or directory)
28565 execve("/bin/cat", ["cat", "*.log", ";", "echo", "hello"], [/* 40 vars */] <unfinished ...>
28565 <... execve resumed>) = 0
这表明整个命令行被传递到第一在字符串中找到可执行文件。 (这是一种独特的执行内容的方式。)
我建议编写一个小型shell脚本,它完全符合您的需求,并从gnome-terminal
-e
命令行选项运行该shell脚本。事情是这样的:
~/bin/cp_first_output.sh
:
#!/bin/sh
cd /home/syntax_error/Desktop/uni_work/
./a.out './exec_me 500'
cp output.txt /home/syntax_error/FILES/first_output.txt
chmod 755
该文件,然后运行:
gnome-terminal --tab -e /home/syntax_error/bin/cp_first_output.sh
我很好奇,如果'; cp输出...内容也被传递给'.a.out'作为命令行参数;尝试使用'strace -o /tmp/out-f gnome-terminal -...'运行该命令并检查'/ tmp/out'文件中是否存在'execve(2)'调用。 – sarnold 2012-01-04 00:31:06
@sarnold execve(2)在文件中不存在...任何想法? – 2012-01-04 00:35:54