problem passing unix variable to c


 
Thread Tools Search this Thread
Top Forums Programming problem passing unix variable to c
# 1  
Old 05-13-2010
problem passing unix variable to c

hi,

i am trying to call a unix script in a c program, this unix script will set a flag, the value of which i would like to return to the calling C program. this is the code that i have written.. the get env functions works if i use other env variables set at session level in unix like "JAVA_HOME" or ORACLE_HOME. it seems like there is a problem in reading the varaible that i set in the program. can any one please help.
in c :

Code:
strcpy ( command  , "sh unixscript.sh   ");
			strcat ( command  ,"filename");
			printf ("running shell script  flsps");
		system ( command );
printf ("value of flpsp_hdr flag is %\n", getenv( "flpsp_flag" ));

shell script :
Code:
#!/bin/sh
filename=$1
header_type1="pattern1"
header_type2="pattern2"
a=`grep $header_type1 $filename`


if [  -z "$a" ]
then 
echo "format one is not present"
else
flpsp_flag=a
echo $flpsp_flag
export flpsp_flag
fi
b=`grep $header_type2 $filename`
if [  -z "$b" ]
then 
echo "format two is not present"
else
flpsp_flag=b
echo $flpsp_flag
export flpsp_flag
fi

Moderator's Comments:
Mod Comment Please use code tags
# 2  
Old 05-13-2010
Environment variables don't work that way. Child processes get a copy of yours, and don't actually share it; changes they make aren't reflected in your own process. You'll have to capture its output in other ways, probably by reading its standard output. See man popen.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing multiple column values to UNIX variable

sqlplus -s $USER_ID@$SID/$PWD<<EOF>sql_1.txt set feedback off set heading off select 114032 as c_1 from dual ; EOF for i in `cat sql_1.txt` do sh script_1.sh $i Currently i am passing one column value to the single unix variable. How can i pass the values from 2... (2 Replies)
Discussion started by: rafa_fed2
2 Replies

2. Shell Programming and Scripting

passing an unix variable to an XML

I need help I have a unix command : VERSION=$(ls -d /vsn/v12.??.??.?? | sort | tail -1) when i do echo $VERSION, i get the exact value, i want. Now i want to use this variable and pass it to an xml. How can i do that? (1 Reply)
Discussion started by: samk
1 Replies

3. Shell Programming and Scripting

Passing a string variable from Unix to Sql Plus

Hi Guys, I am trying to pass a string variable from Unix shell script to sqlplus as a parameter. I have tried using single quotes with the variable name but it does not work. Please help me with it. I am using BASH. My code: Your help is much appreciated. Thanks, shil (2 Replies)
Discussion started by: infintenumbers
2 Replies

4. Shell Programming and Scripting

Problem while passing variable

Within a shell im starting a terdata BTEQ session #!/bin/ksh set -x TEMP_DATABASE=`head -6 /home/karthik/para.txt|tail -1` TEMP_TABLE=`head -7 /home/karthik/para.txt|tail -1` bteq<<EOF .LOGON TEST/karthik,********; .EXPORT FILE=test1.txt; .set heading '' .set titledashes off; ... (4 Replies)
Discussion started by: mkarthykeyan
4 Replies

5. Shell Programming and Scripting

Passing unix variable to oracle parameters

Please help me how to pass some unix vairable to oracle. I have used below , but not displaying passed (inval) value. calling() { sqlplus -s $1/$2@$3 <<EOF begin exec call_sql($4); end; exit EOF } calling user pwd inst value1... (17 Replies)
Discussion started by: Jairaj
17 Replies

6. Shell Programming and Scripting

Passing the unix variable to sqlplus

Hi, I am writing a script which creates an external table using a shell script. My requirement is like this. Usage: . ./r.ksh <table_name> - this should create an external table. e.g . ./r.ksh abc - this should create an external table as abc_external. How do i achieve this? Please... (5 Replies)
Discussion started by: Anaramkris
5 Replies

7. Shell Programming and Scripting

Problem passing a specific variable to sed

Hi, I'm a bit of sed n00b here. My issue is as follows: I'm trying to pass a variable to sed so that all instances of this variable (in a text file) will be replaced with nothing. However, the value of this variable will always be a folder location e.g. "C:\Program Files\Folder1" I... (5 Replies)
Discussion started by: Mr_Plow
5 Replies

8. UNIX for Advanced & Expert Users

Passing a unix variable value to a Plsql function

Suppose I have a unix variable called RGNM which is holding a value. Now I want to call a plsql function in my script. THis plsql function takes one IN parameter. I want to pass my UNIX VARIABLE Value to the plsql function. Can i just give it by giving $RGNM in the function after calling sqlplus... (1 Reply)
Discussion started by: cobroraj
1 Replies

9. UNIX for Advanced & Expert Users

passing unix variable to sqlplus without a file name

Hi, I want to input unix variable to sqlplus.The following is working fine sqlplus username/password @dummy.sql param1 param2 << EOF create user $1 identified by $2; EOF But I dont want any file name to be passed,I just want to pass the parameter. Is there any way to that?? Thanks... (3 Replies)
Discussion started by: sakthi.abdullah
3 Replies

10. Programming

Passing C Variable To Unix

I want to pass a variable set in my c program to a shell script (which will also be invoked or initiated from the same C program using the C's system command). Is it possible ? :confused: (3 Replies)
Discussion started by: kapilv
3 Replies
Login or Register to Ask a Question