1833756 Members
2817 Online
110063 Solutions
New Discussion

Re: xterm + script

 
Vasudevan MV
Frequent Advisor

xterm + script

Hi,

1. Can any one tell me why this error "xterm: can't execvp /abc.sh" is appearing on the xterm window when I ran this command on the prompt "$ xterm -e abc.sh"?.

2. The abc.sh script exits with value "5" but after execution of this abc.sh with xterm its returning only 0 when I did echo $?. How do I get the return value 5 to the calling shell?

Thanks
Vasu
7 REPLIES 7
Steven Sim Kok Leong
Honored Contributor

Re: xterm + script

Hi,

Try this:

# exec xterm -e "abc.sh 2\> /tmp/abc.err"
# ERRORCODE=`cat /tmp/abc.err`

Hope this helps. Regards.

Steven Sim Kok Leong
Vasudevan MV
Frequent Advisor

Re: xterm + script

Steven,

I have tried your commands, but still I am getting the same error "xterm: can't execvp /abc.sh 2\>/dev/null".

Thanks
Vasu
T G Manikandan
Honored Contributor

Re: xterm + script

Add the line to your script as the first line.example to execute it in bourne shell

#!/bin/sh
Steven Sim Kok Leong
Honored Contributor

Re: xterm + script

Hi,

Make sure that your script has executable permissions i.e.

bash-2.05a$ chmod +x ./abc.sh

You can fix the return code issue by using a wrapper script i.e. startabc.sh:

bash-2.05a$ cat ./abc.sh
echo this is a test
adfasdf
bash-2.05a$ ./abc.sh
this is a test
./abc.sh: adfasdf: command not found
bash-2.05a$ echo $?
127
bash-2.05a$ rm /tmp/abc.err
bash-2.05a$ cat ./startabc.sh
./abc.sh
echo "$?" > /tmp/abc.err
bash-2.05a$ xterm -e ./startabc.sh
bash-2.05a$ cat /tmp/abc.err
127

Make sure that ./abc.sh and ./startabc.sh has executable permissions.

Hope this helps. Regards.

Steven Sim Kok Leong
Vasudevan MV
Frequent Advisor

Re: xterm + script

Steven,

My script looks like this

startabc.sh
--------------
xterm -e ./abc.sh
echo $?

abc.sh
-------
echo "hello"
exit 5

When I ran startabc.sh it always return 0 & in the xterm session sometimes the error is coming up "xterm: can't execvp /abc.sh"?.

Thanks
Vasu

Steven Sim Kok Leong
Honored Contributor

Re: xterm + script

Hi,

> xterm -e ./abc.sh
> echo $?

xterm spawns off a separate shell that does not return the exit code (return code) to the parent shell that spawned off xterm.

Thus, to workaround this limitation, you have to echo the "$?" to a file and read from that file in your startabc.sh script:

./startabc.sh:
=============
./abc.sh
echo "$?" > /tmp/abc.err

Then you run this:

# xterm -e ./startabc.sh
# cat /tmp/abc.err # this displays the return code

If you want, you can put these two lines in another wrapper so that the return code is automatically displayed.

Hope this helps. Regards.

Steven Sim Kok Leong
Steve Steel
Honored Contributor

Re: xterm + script

Hi

try adding the pathname to xterm and abc.sh


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)