![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| returning values from shell script to calling C program | nehamore | Shell Programming and Scripting | 2 | 02-04-2008 11:09 AM |
| Returning Strings from C program to Unix shell script | venkatesh_sasi | High Level Programming | 24 | 11-28-2007 04:48 AM |
| shell program for sorting strings in an alphabetical order | bp_vanarse | Shell Programming and Scripting | 1 | 10-25-2006 11:41 AM |
| returning to the parent shell after invoking a script within a script | gurukottur | Shell Programming and Scripting | 5 | 09-26-2006 08:05 AM |
| Returning Values (shell Script) | jennifer01 | Shell Programming and Scripting | 3 | 11-29-2001 06:31 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
Iam calling a C program from a Unix shell script. The (C) program reads encrypted username/password from a text file , decrypts and returns the decrypted string. Is there any way i can return the decrypted string to Unix shell program. My shell script uses the output of the program to login to oracle DB. C programs main() function returns int. How is it possible to return a String from a C program? Please help me. Thanks in advance. Rao. |
|
||||
|
Thank you very much reborg.
I am going to follow whatever approach you suggested. I have a small concern here. In future, if some one comes and adds one more printf to the program (for debugging purpose), the script won't function properly right?? Is it possible to write the output values to a common memory which can be used by Unix shell as well as C program. Once the C program writes the output to that common memory , can Unix pick the values? Since the program deals with passwords I can't write the output to a temp text file so that shell script reads the file and delete it. How about writing the values to environment variables from C and accessing from Unix? Iam new to Unix and C, please correct me if my questions are dumb. Thanks Rao. |
|
|||||
|
That's not really the way things are done in Unix. There is an old tenet in Unix programming which says, if you have nothing to say don't say anything, in other words if there is no reason for output from your program don't have any. So taking that into account you should not have any debugging output. That said you could make sure you have the correct information by making sure the outut of the "correct" printf has a well defined format, by prefixing it with something, like this. Code:
printf("DECRYPTED_DATA %s", decrypted_password);
he the script would for example become Code:
clear_text_password=$(my_C_program | awk '/DECRYPTED_DATA/{print $2}' )
if [[ $? -eq 0 ]] ; then
#The password was returned correctly
#Do whatever you like here
echo "The decrypted value is: ${clear_text_password}
else
echo "Password decryption failed"
exit 1
fi
|
|
|||||
|
Quote:
satguyz, you should read up on the use of stdout and stderr for both your application and your shell script. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|