473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Code:
===
Expand|Select|Wrap|Line Numbers
  1. Perl file 
  2. my $diff1=system("sh diff.sh");
  3. my $diff2=system("sh diff1.sh");
  4.  
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 .
Expand|Select|Wrap|Line Numbers
  1. diff1.sh
  2. -------
  3. a=diff aaa ccc
  4. diff.sh
  5. --------
  6. b=diff aaa bbb
  7.  
  8.  
  9.  
  10. 122 $> cat aaa 
  11. 1hi hello
  12. 123 $> cat bbb
  13. hi hello
  14. 125 $ cat ccc
  15. 1hi hello
  16.  
  17. 120 $ diff aaa ccc
  18. echo $?
  19.  
  20.  
  21.  
  22. diff aaa bbb
  23. 1c1
  24. < 1hi hello
  25. ---
  26. > hi hello
  27. Exit 1
  28.  
  29.  echo $?
  30. 1
  31.  
Nov 11 '09 #1
4 5182
numberwhun
3,509 Expert Mod 2GB
You are corrent, the system() command does return the return code (1 or 0) or the command it ran. My suggestion would be to use backtics in place of the system command. Its another way to execute system level commands, but you can get the output instead.

Expand|Select|Wrap|Line Numbers
  1. my $diff1 = `sh diff.sh`;
  2. my $diff2 = `sh diff2.sh`;
  3.  
Regards,

Jeff
Nov 12 '09 #2
babp
10
Hi Jeff ,
Thanks for the response since i jhave explained already I need exit status as 1 or 0.

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 .
Nov 12 '09 #3
numberwhun
3,509 Expert Mod 2GB
Ok, I guess I can say that I am now confused. The system() function does just that. If the script/command that was run exits normally, then it returns zero. Otherwise it returns a 1.

If the script you are running returns a value, then you would use backtics. Otherwise, I highly suggest you re-write your shell scripts in Perl to do what you need to do. It will preempt any and all confusion on what you are really wanting.

Regards,

Jeff
Nov 13 '09 #4
babp
10
Hi jeff ,
Thanks for the reply i got the solution :

ACE25C1: ...Monday/package 154 $ cat diff.pl
my $a=system("sh diff.sh");
print $a;


ACE25C1: ...Monday/package 155 $ cat diff.sh
diff aaa bbb
if [ `diff aaa bbb | grep -c "^1c1$"` -eq 0 ]
then
exit 0
else
exit 1
fi
Nov 20 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: julio Morales | last post by:
Hi! When a user is in a MSAccess form, with the values of a registry, and click on 'send this', I need to send the id. value of such registry to a perl script with visual basic. I can exec a...
2
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info...
1
by: speedster | last post by:
Hi. I need some help converting some php to perl. $meminfo = shell_exec( "free -o" ); I need to execute "free-o" in shell and get the results. It grabs memory information about a linux...
0
by: David Roche | last post by:
Hello, I searched all through Google Groups, Google, and the Postgres docs, but to no avail. I hope someone can help me out here! I have a file that contains SQL, and some Postgres-specific...
2
by: prakashpb | last post by:
Hello All, I am new to perl. I have to write some code in perl on windows. I have to invoke/run a shell file sample.sh from within perl file. When the perl while is executing, it should run to...
1
by: looza | last post by:
Hi All, I have a bunch of shell script files that use a common shell script file that contains certain global variables that are declared and initialized or derived by some arithmatic. I have...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
4
by: devi thapa | last post by:
Hi, I am executing a python script in a shell script. The python script actually returns a value. So, can I get the return value in a shell script? If yes, then help me out. Regards, Devi
4
by: kat248637 | last post by:
suppose i have a variable in shell script like a="prashant" and i want to assign this variable into another variable like b=$a,which is in perl script.after run perl script the value of b should be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.