call external program from script
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > call external program from script




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    call external program from script  
dafella24


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:22 AM

I want to assign the return value from an external c program to a
varible in my bash script. (Ex. I have a program call foo (executable)
returns an int. Normall you just do ./foo arg to invoke it in a shell,
but now I want to do something like $ret=foo arg in a script.
Helpppppppp!

thanks





[ Post a follow-up to this message ]



    Re: call external program from script  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:22 AM

bi90261@yahoo.com (dafella24) writes:

> I want to assign the return value from an external c program to a
> varible in my bash script. (Ex. I have a program call foo (executable)
> returns an int. Normall you just do ./foo arg to invoke it in a shell,
> but now I want to do something like $ret=foo arg in a script.

./foo
ret=$?

--
Måns Rullgård
mru@mru.ath.cx





[ Post a follow-up to this message ]



    Re: call external program from script  
SM Ryan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:13 PM

bi90261@yahoo.com (dafella24) wrote:
# I want to assign the return value from an external c program to a
# varible in my bash script. (Ex. I have a program call foo (executable)
# returns an int. Normall you just do ./foo arg to invoke it in a shell,
# but now I want to do something like $ret=foo arg in a script.
# Helpppppppp!

#!/bin/sh
root=`ls -ld /`
echo ---------------------------
st=$?
echo 'root ls: ' $root
echo 'ls status: ' $st
echo ---------------------------
stdout=`mkdir /error`
st=$?
echo 'stdout: ' $stdout
echo 'status: ' $st
echo ---------------------------
stdout=`mkdir /error 2>&1`
st=$?
echo 'stdout+stderr: ' $stdout
echo 'status: ' $st
echo ---------------------------


---------------------------
root ls:  drwxrwxr-t 36 root admin 1224 22 Sep 06:47 /
ls status:  0
---------------------------
mkdir: /error: Permission denied
stdout:
status:  1
---------------------------
stdout+stderr:  mkdir: /error: Permission denied
status:  1
---------------------------


For ksh and derivatives, you can use nestable $(...) as well as `...`.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
One of the drawbacks of being a martyr is that you have to die.





[ Post a follow-up to this message ]



    Re: call external program from script  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:13 PM

2004-09-23, 11:33(-00), SM Ryan:
[...]
> #!/bin/sh
> 	root=`ls -ld /`
> 	echo ---------------------------
> 	st=$?

You get echo status there.

[...]
> For ksh and derivatives, you can use nestable $(...) as well as `...`.
[...]

`...` are nestable too, but in a less convenient way:

echo `echo \`echo \\\`echo foo\\\`\``

$(...) is better that `...` not that much because they are
nestable but because they don't interfer with backslash
processing.

ls '\'

for instance, lists the '\' file when outside backticks, but
lists the '' file when inside:

$ ls '\'
\\: No such file or directory
$ : `ls '\'`
\: No such file or directory
$ : $(ls '\')
\\: No such file or directory

--
Stephane





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:45 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register