473,396 Members | 1,982 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.

invoking unix command in perl

blackgoat
I have to run a command in unix. And I have to match this expression from whatever output I get. I tried doing the following:

Expand|Select|Wrap|Line Numbers
  1. my $var = 'command';
  2. my ($exp) = $var =~ m/pattern/;
The same is followed by a html script in which the value of $exp must appear. But I am unable to do so...

Can u pls help! what is the best way to do this??

Thanks

BG
Mar 5 '10 #1
8 2838
jkmyoung
2,057 Expert 2GB
Are you using the right punctuation?

It looks like you're using apostrophes ' instead of backticks ` (under ~, and next to the 1 on most keyboards)
Mar 5 '10 #2
yeah I know .... I fixed that bug but it still doesn't work! is that the ony mistake? or am I doing some other mistake as well??

BG
Mar 6 '10 #3
jkmyoung
2,057 Expert 2GB
Have you tried outputting var? Eg, are you getting output?
(It could be the case that the output pipes to std error, instead of std out.)

Also are you sure your regex is correct? What's in the value of your pattern?
Mar 8 '10 #4
The regex is working otherwise.. when I try it in a perl script editor separately by giving a dummy paragraph. Its only when I try embedding it in my html script that I have trouble. Strangely enough I get no errors on debugging my html file... and yet the output of my regex is totally ignored when I run it!
Mar 9 '10 #5
RonB
589 Expert Mod 512MB
You haven't provided us enough info to help you.

Please post:
1) your entire script
2) what input is it receiving
3) what you expect it to do
4) what it is doing that it shouldn't
5) what it is not doing that it should
6) what errors/warnings are you recieving
Mar 9 '10 #6
i cant post my entire script coz it has a number of interlinked scripts plus some of the data is confidential. however i will give u the script in which i must incorporate this command:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
  3. use CGI;
  4.  
  5. $var = `COMMAND`;
  6. my ($var1) = $var =~ m/pattern/;
  7.  
  8. print "Content-type:text/html\n\n
  9.  
  10. <html>
  11.  
  12. <head>
  13.  
  14. <title>TITLE</title>
  15.  
  16. <script language='Javascript'>
  17.  
  18. function validate_required(field,alerttxt)
  19.         {
  20.         with (field)
  21.                 {
  22.                 if (value==null||value==\"\")
  23.                         {
  24.                         alert(alerttxt);return false;
  25.                         }
  26.                 else
  27.                         {
  28.                         return true;
  29.                         }
  30.                 }
  31.         }
  32.  
  33. function validate_form(thisform)
  34.         {
  35.         with (thisform)
  36.                 {
  37.                 if (validate_required(rundir,\"Runpath must be filled out!\")==false)
  38.                         {
  39.                         rundir.focus();return false;}
  40.                         }
  41.                 }
  42. </script>
  43.  
  44. </head>
  45.  
  46. <body style=\"background-color:FFF0F5\"><form name='form1' action='http://cdsiweb/cgi-bin/elc/random_num.pl' method='POST' onsubmit=\"return validate_form(this)\">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
  47.  
  48. # I want to print the output of 'var1' here
  49.  
  50. <h2><div align=\"center\"><font color='CC3300'>HEADING</font></div></h2><br><br>
  51.  
  52. <div align=\"center\">
  53. <table cellpadding=\"10\">
  54.         <tr>
  55.                 <td>
  56.                         <font color='CC3300'><b>Enter rundir path</b>:</font>
  57.                 </td>
  58.  
  59.                 <td>
  60.                         <input type=text name=rundir size=50 onChange=\"valid_data(this.name)\">
  61.                 </td>
  62.         </tr>
  63.  
  64.         <tr>
  65.                 <td>
  66.                         <font color='CC3300'><b>Select Version</b>:</font>
  67.                 </td>
  68.  
  69.                 <td>
  70.                          OPTIONS
  71.                 </td>
  72.         </tr>
  73.  
  74.  
  75.         <tr>
  76.                 <td>
  77.                         <font color='CC3300colorcolor'><b>Group</b>:</font>
  78.                 </td>
  79.                 <td>
  80.                         OPTIONS
  81.                 </td>
  82.         </tr>
  83.  
  84.         <tr>
  85.                 <td></td>
  86.  
  87.                 <td>
  88. <input type=\"submit\" value=\"Submit\" />
  89.                 </td>
  90.         <tr>
  91.                 <td></td>
  92.  
  93.                 <td>
  94.                          <form name=user_log action=\"\" method=POST>
  95.                                 <input type=submit name=submit value=\"User Log\">
  96.                         </form>
  97.                 </td>
  98.         </tr>
  99. </table>
  100.  
  101. </div>
  102.  
  103. </body>
  104.  
  105. </html>"
I assure you that the regex pattern is working fine as I have tested it. Its only I can not embedded in the script.

The above mentioned COMMAND is to be run in unix that results in some textual output from which the pattern is recognised.
Mar 9 '10 #7
hey! do I need to use @ARGV in some way? how??
Mar 9 '10 #8
RonB
589 Expert Mod 512MB
Before I point out everything that you're doing wrong in that code, it would be better for you to create a short and complete test script that demonstrates the problem.

Your test script, and in fact EVERY Perl script you write should include the warnings and strict pragmas. So, your test script should look like this:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
  6. use CGI;
  7.  
  8. my $cgi = CGI->new;
  9. print $cgi->header,
  10.       $cgi->start_html('test');
  11.  
  12. warningsToBrowser(1);
  13.  
  14. # output the raw command that you intend to execute
  15. # execute the command
  16. # output the results
  17. # apply your regex
  18. # output the new results
  19.  
  20. print $cgi->end_html;
Mar 9 '10 #9

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

Similar topics

3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
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...
0
by: Danny Jensen | last post by:
I need to test if certain processes on a unix box were running. I wanted to use whatsup gold to do the testing. First I needed to go to the whatsup configure>monitors & services menu to add this...
8
by: TonyHa | last post by:
Hello, Does any one have using Python to write a Unix "diff" command for Window? Tony Ha.
0
by: niket patel | last post by:
Hi There is a unix server and and we access unix and perform its commond using exceed or ftp through dos. Now i want to create an application in Visual Studio C#.Net 2003 such that i can create...
2
by: George Ter-Saakov | last post by:
Hi, Somehow i need to call perl script that is on another Unix machine form my C# code. The problem is that this perl script is executed form command line (no apache on that machine). Is...
1
by: Thierry Missimilly | last post by:
Hi Postgres users, I wonder to know if it is possible to launch a Perl program or a unix comand in a trigger function. I have tried to do that in a C trigger developed with the SPI function....
1
by: LaoDe | last post by:
Hi, I want to catch a select-result into perl-variable, like this (on Linux): $C = system ("sqlplus $DBUSER/$DBPW \@getcolnam.sql $TABNAM $TABOWNER "); Wenn I run this, I see Oracle's...
223
by: Pilcrow | last post by:
Given that UNIX, including networking, is almost entirely coded in C, how come so many things are almost impossible in ordinary C? Examples: Network and internet access, access to UNIX...
1
by: KiSSFRo | last post by:
Hi all, I was wondering if someone could tell me which is the best command to use to run a unix command and to hide the error output from the shell. I'd also like to be able to tell if the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.