gnome-terminal error
-
13-04-2021 - |
Pergunta
I am trying to open a terminal that would execute a code and copy the output files to a destination folder but for some reason only the executable is running and the copy command doesnt work, but when I execute each alone it works...
Can anyone help me detect the syntax mistake I have?
The command line is:
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"
where ./exec_me is a parameter to a.out and 500 is a parameter to exec_me
Thanks =)
Solução
I ran a similar test myself:
$ 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
This shows that the entire command line is being passed to the first executable found in the string. (Which is a ... unique ... way of executing content.)
I suggest writing a small shell script that does exactly what you want and run that shell script from the gnome-terminal
-e
command line option. Something like this:
~/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
that file and then run:
gnome-terminal --tab -e /home/syntax_error/bin/cp_first_output.sh
Outras dicas
It looks like gnome-terminal
doesn't use shell to execute those commands. If you want to use ;
, you need invoke it through the shell explicitly.
Try:
gnome-terminal -e "bash -c 'command1 ; command2'"
Or:
echo "command1 ; command2" > tmp.sh
gnome-terminal -e "bash tmp.sh"
Try to separate the two commands by using "\" (without quotes)