侏儒终端错误

时间:2012-01-04 00:26:27

标签: linux gnome gnome-terminal

我正在尝试打开一个执行代码并将输出文件复制到目标文件夹的终端,但由于某种原因,只有可执行文件正在运行且复制命令不起作用,但是当我单独执行每个代码时它工作..

任何人都可以帮助我检测我的语法错误吗?

命令行是:

gnome-terminal --working-directory=/home/syntax_error/Desktop/uni_work/ --tab -e "./a.out './exec_me 500' ; cp output.txt /home/syntax_error/FILES/first_output.txt"

其中./exec_me是a.out的参数,500是exec_me的参数

谢谢=)

3 个答案:

答案 0 :(得分:4)

看起来gnome-terminal不使用shell来执行这些命令。如果要使用;,则需要通过shell明确调用它。

尝试:

gnome-terminal -e "bash -c 'command1 ; command2'"

或者:

echo "command1 ; command2" > tmp.sh
gnome-terminal -e "bash tmp.sh"

答案 1 :(得分:4)

我自己也做过类似的测试:

$ 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

这表明整个命令行正在传递给字符串中的 first 可执行文件。 (这是......唯一的...执行内容的方式。)

我建议编写一个小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

答案 2 :(得分:0)

尝试使用“\”(不带引号)

来分隔这两个命令