How to return a value of a variable from shell script to perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to return a value of a variable from shell script to perl script
# 1  
Old 11-12-2009
Bug How to return a value of a variable from shell script to perl script

HI ,
Is there any way to return a value of variable from shell to perl script.

Code:
===
Perl file
my $diff1=system("sh diff.sh");
my $diff2=system("sh diff1.sh");

I need exit status of below commands

i.e 0 and 1 respectively.

Since in both the cases diff is working so system command will return 0 .

diff1.sh
-------
a=diff aaa ccc
diff.sh
--------
b=diff aaa bbb



122 $> cat aaa
1hi hello
123 $> cat bbb
hi hello
125 $ cat ccc
1hi hello

120 $ diff aaa ccc
echo $?
0


diff aaa bbb
1c1
< 1hi hello
---
> hi hello
Exit 1

echo $?
1




If i'll use backtick it'll return the diff output like below:
1c1
< 1hi hello
---
> hi hello

But I need script to return a value like 1 if it finds any diffrence between two files and 0 if it doesnot find any diffrence between two files .
# 2  
Old 11-17-2009
StdOut, StdErr - you can catch them.
Return code - a value which is 0 or !0. 0=SUCCESS, !0=FAILURE (according to POSIX). There are exceptions like diff. Return code should be between 0 and 127 but might be different.
There are other possibilities as well... google for inter-process communication.
# 3  
Old 11-20-2009
Hi adderek ,
Thanks for the reply

Can you please help me to sort out this
I am running an application XXXX , and when it starts i am passing a file name called "connect.spb" and after the application connects to the server i am sending filename "accept.spb" as a parameter.

BL31DL385:$ ./XXXX

This is XXXX (Reproducer by Order or RelaY)


XXXX> @connect.spb

XXXX>Opening connect.spb

Script> SET TCPIP /LOCAL_PORT=15331
Initialised TCP Listener on BL31DL385 (port: 15331)


>@accept.spb

XXXX> Opening accept.spb

So basically Input parameters are @connect.spb and @accept.spb.
After getting first string application will connect to the client ,
Then wait for the input and when accept parameter is given communication established succesfully.



MyQuestion##can we automate this using a script which will first run the application XXXX, and then pass the connect.spb and accept.spb as input
# 4  
Old 11-23-2009
Check "expect" utility. It should fit you.
This application XXXX seems to be something not designed for your purpose - since it lacks propper interface. Check if you can replace XXXX with something different.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

2. Shell Programming and Scripting

Using variable from shell script in perl file

Hey, So I have a shell script that outputs some variables, call them $a and $b. I know in shell scripting if I wanted to use the variables in another shell script I'd do sh code.sh "$a" "$b" How can I do something similar with perl? (2 Replies)
Discussion started by: viored
2 Replies

3. Shell Programming and Scripting

Return variable value from a script running in background

I have a script which runs a script in the background. Now the script running in background returns some variable value and i want to catch return value in the parent script. e.g. Parent Script : #!/bin/bash ./Back.sh & pid=$! echo "a=$a" echo "b=$b" echo "d=$((a+b))" wait $pid ... (4 Replies)
Discussion started by: Shaishav Shah
4 Replies

4. Shell Programming and Scripting

Assigning return value of an embedded SQL in a shell script variable

I've a script of the following form calling a simple sql that counts the no of rows as based on some conditions. I want the count returned by the sql to get assigned to the variable sql_ret_val1. However I'm finding that this var is always getting assigned a value of 0. I have verified by executing... (1 Reply)
Discussion started by: MxC
1 Replies

5. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

6. Shell Programming and Scripting

Simple script to return environment variable

HI , In the below script I am trying to return the value of the environment variable TIBCO_HOME to the caller #! /usr/bin/csh set VAR_NAME=$1 echo VAR_NAME On the aix console.. set to setenv TIBCO_HOME /app/tibco When I execute the script... myscript.sh TIBCO_HOME, the script... (5 Replies)
Discussion started by: bce_groups
5 Replies

7. Shell Programming and Scripting

Get return value from PERL script calling from KSH

All: I am calling a PERL script from KSH. I need specific codes to be returned by the PERL Script. For ex: Ksh ----- result=`test.pl $FILE` My idea is to get the value of result from the test.pl, by specifically making the test.pl to print the return code. Since I had some other print... (1 Reply)
Discussion started by: ucbus
1 Replies

8. Shell Programming and Scripting

How to return value in shell script

im using bourne shell In file scriptA i add a new function, test_return() test_return() { a=1 return $a } when i try execute , a='/''/scriptA test_return echo $a its give me error.. scriptA: cannot return when not in function ist any solution for this problem.. How... (1 Reply)
Discussion started by: neruppu
1 Replies

9. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

10. Shell Programming and Scripting

How to use substr to return data into a shell script variable?

I'm writing a shell script in which I need to be able to pull a portion of the file name out. I'm testing with the following code: x="O1164885.DAT" y=`ls -ltr *${x}|awk '{print substr($0,3)}'` echo ${x}|awk '{print substr($0,3)}' echo "y="$y I can echo it to the screen just fine but I... (3 Replies)
Discussion started by: ttunell
3 Replies
Login or Register to Ask a Question