Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] system command in Perl

Expand Messages
  • Jeff Pinyan
    ... Two problems. First: You have *single quotes* around $command, which means it won t be expanded as a variable, it will literally be the characters
    Message 1 of 4 , Oct 24, 2008
    • 0 Attachment
      On Fri, Oct 24, 2008 at 4:16 PM, aditi gupta <aditi9783@...> wrote:

      > my $command = "<executable_name> <argument_list>";
      > system('$command') or die "couldn't execute $command:$!\n";
      >

      Two problems.

      First: You have *single quotes* around $command, which means it won't be
      expanded as a variable, it will literally be the characters *$command*.
      That's not what you want.

      Second: system() returns a true (non-zero) value when something goes *wrong
      *. It returns false (zero) on success. This is "backwards" and must be
      handled that way:

      system($command) == 0 or die "could not execute $command: $!\n";
      # or
      system($command) and die "could not execute $command: $!\n";

      --
      [Mary said,] "Do whatever he tells you." ~ John 2:5
      The Cross Reference - http://thecrossreference.blogspot.com/
      Nos autem praedicamus Christum crucifixum (1 Cor 1:23)


      [Non-text portions of this message have been removed]
    • Arun Pandey
      Well the system commands returns the exit status of the executed program . In your case the external program is running successfuly so its exit status is 0
      Message 2 of 4 , Oct 24, 2008
      • 0 Attachment
        Well the system commands returns the exit status of the executed program . In your case the external program is running successfuly so its exit status is 0 which means a clean exit hence your code after the 'or' operator gets executed.
        Hope that helps.

        --- original message ---
        From: "aditi gupta" <aditi9783@...>
        Subject: [PBML] system command in Perl
        Date: 25th October 2008
        Time: 1:47:07 am

        Hello All:

        I was trying to run an executable program (in Unix) using the system command. (Successful execution of this executable writes out <.out> files in the directory).

        The code is as follows:
        ===BEGIN===

        my $command = "<executable_name> <argument_list>";
        system('$command') or die "couldn't execute $command:$!\n";

        ===END===
        The command runs fine when executed from the command prompt, but through Perl program, its giving the "couldn't execute..." error message.

        Then I tried another system call through Perl:

        system('who') or die "couldn't execute: $!\n";

        And this time, it executes the "who" command as from the prompt, but also prints out the "couldn't execute: " error message.

        And suggestions as to what might be going on?


        I tried using "open" too
        ===
        open (CMD, "$command |") or die "couldn't execute\n";
        close CMD;
        ===
        and this works fine when the executable is to be run on smaller sized input data, but gives segmentation fault otherwise.

        Any comments/suggestions are highly appreciated.

        Thank you!

        Aditi




        Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/

        [Non-text portions of this message have been removed]


        "Legal Disclaimer: This electronic message and all contents contain information from Cybage Software Private Limited which may be privileged, confidential, or otherwise protected from disclosure. The information is intended to be for the addressee(s) only. If you are not an addressee, any disclosure, copy, distribution, or use of the contents of this message is strictly prohibited. If you have received this electronic message in error please notify the sender by reply e-mail to and destroy the original message and all copies. Cybage has taken every reasonable precaution to minimize the risk of malicious content in the mail, but is not liable for any damage you may sustain as a result of any malicious content in this e-mail. You should carry out your own malicious content checks before opening the e-mail or attachment."
        www.cybage.com
      • aditi gupta
        Wow. Thank you guys for the input! I see the problem now. :) Best Aditi ... From: Jeff Pinyan Subject: Re: [PBML] system command in Perl
        Message 3 of 4 , Oct 25, 2008
        • 0 Attachment
          Wow. Thank you guys for the input! I see the problem now. :)

          Best
          Aditi
          --- On Sat, 25/10/08, Jeff Pinyan <japhy.734@...> wrote:
          From: Jeff Pinyan <japhy.734@...>
          Subject: Re: [PBML] system command in Perl
          To: perl-beginner@yahoogroups.com
          Date: Saturday, 25 October, 2008, 1:52 AM











          On Fri, Oct 24, 2008 at 4:16 PM, aditi gupta <aditi9783@yahoo. co.in> wrote:



          > my $command = "<executable_ name> <argument_list> ";

          > system('$command' ) or die "couldn't execute $command:$!\ n";

          >



          Two problems.



          First: You have *single quotes* around $command, which means it won't be

          expanded as a variable, it will literally be the characters *$command*.

          That's not what you want.



          Second: system() returns a true (non-zero) value when something goes *wrong

          *. It returns false (zero) on success. This is "backwards" and must be

          handled that way:



          system($command) == 0 or die "could not execute $command: $!\n";

          # or

          system($command) and die "could not execute $command: $!\n";



          --

          [Mary said,] "Do whatever he tells you." ~ John 2:5

          The Cross Reference - http://thecrossrefe rence.blogspot. com/

          Nos autem praedicamus Christum crucifixum (1 Cor 1:23)



          [Non-text portions of this message have been removed]



























          Connect with friends all over the world. Get Yahoo! India Messenger at http://in.messenger.yahoo.com/?wm=n/

          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.