Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i return a value from an exe, which is run from a script file

Status
Not open for further replies.

kfhee

Programmer
Jul 15, 2001
7
AU
example,

ret.exe
int main()
{
return 7;
}

scr.csh
set num = `ret`
echo $num

The return value is not set into num

Thanks for assistance.
 
Hi:

I'm not a csh person, but I think what you want is to set the exit code in the "C" program, and not return:

ret.exe:

int main()
{
exit(7);
}

You then want to look at the exit code, $?, in the shell:

ret.exe
echo $? # Using SCO Open Server V

Regards,

Ed
 
olded's way is correct, but if you want to pass the value to another programm (say wish)
you cannot use it, because the wish will
complain about the exit status; so back to kfhee's version:

int main(int argc, char **argv)
{
printf("%d\n",7);
exit(0);
}

#!/bin/sh

ret=`exec`; echo $ret


jm
 
Guys,

the exe still does not return value to the var, like

set var=`exec ret.exe`

still does not work
 
In C (file ret.c):
Code:
int main(int argc, char *argv[])
{
    printf("%d\n", 5);
    return 7;
}

In t?csh:
Code:
set val1 = `ret`
set val2 = $status
echo "val1 = $val1" # Should be 5 (executable output)
echo "val2 = $val2" # Should be 7 (executable exit status)

In (k|ba)?sh:
Code:
val1=`ret`
val2=$?
echo "val1 = $val1" # Should be 5 (executable output)
echo "val2 = $val2" # Should be 7 (executable exit status)
 
It works, i have tested on csh, thanks a lot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top