Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

system command with arguments Error

by ansh batra (Friar)
on Jan 07, 2013 at 17:34 UTC ( #1012071=perlquestion: print w/replies, xml ) Need Help??
ansh batra has asked for the wisdom of the Perl Monks concerning the following question:

hello monks
when i run the perl script which have
system("perl $manuf $series $model $url $kb_color_style_name $kb_color_image_url $kb_color_image_id")==0 or die "cant run!!";
i get an error : system cannot find the file specifies
where as both the perl files are in the same folder
please help

Replies are listed 'Best First'.
Re: system command with arguments Error
by blue_cowdawg (Monsignor) on Jan 07, 2013 at 19:15 UTC

    boo hiss! I hate seeing one Perl script calling another. Sloppy...

    What might help you out is to do one of two things in descending levels of difficulty:

    • Convert the functionality of to a module
    • Convert the functionality of to a sub
    In the first case you'd have to take the time to examine what does and write a module for it that does the same thing. Not quite as easy as just doing
    $ cp
    you'd actually have to wrap the logic in some fashion that makes sense. For instance, here's a small Perl script I want to convert.
    #!/usr/bin/perl -w use strict; # # This is the main part of the script here... my ($parm1,$parm2,$parm3,$parm4)=@ARGV; func1($parm1,$parm2) $func2($parm3,$parm4) exit(0); sub func1{ #logic here. } sub func2{ #logic here } | | etc |
    which could become:
    package Cart; sub new { shift; my $self={}; bless $self,"Cart"; return $self; } sub doCart { my ($self,$parm1,$parm2,$parm3,$parm4)=@_; # main part of original script goes here } sub func1{ } sub func2{ } 1;
    You could then invoke it as:
    #!/usr/bin/perl -w use strict; use lib qw @ /path/to/directory/my/binary/runs/from @; use Cart; my $cart = new Cart(); | | hand waving | $cart->doCart($arg1,$arg2,$arrg3,$arrr_ahoy_matey); | | etcetera... |
    the important part is the use lib part which causes Perl to look for your module where it lives. In this case I'm saying the same place the script lives. You could also do
    use FindBin qw/ $Bin /; use lib "$Bin"; | etc

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

        I was just wondering if it's in the same directory, maybe the permissions are not sufficient, and you should source the file?

        #!/usr/bin/perl use strict; use warnings; print system (qw/.\/ filename1.out/); print system (qw/.\/ filename2.out/);
Re: system command with arguments Error
by Old_Gray_Bear (Bishop) on Jan 07, 2013 at 18:00 UTC
    It appears that you are not in the folder that you think you are when the system() is executed. Please post a small, self-contained example of the code you are using. and we can go from there.

    I Go Back to Sleep, Now.


      they are in the same directory. i have checked it .
      and my code is running fine but when it reaches system("perl .......")==0 or die "cant run!!";
      it outputs cant run!!

        There's a less-baudlerized version of this statement:
        You can't just make stuff up and expect Perl to understand.
Re: system command with arguments Error
by Sandy (Curate) on Jan 07, 2013 at 18:01 UTC
    Try this for debugging:
    my $cmd = "perl $manuf $series $model $url $kb_color_style_nam +e $kb_color_image_url $kb_color_image_id"; print "cmd is $cmd\n"; system($cmd) == 0 or die "cant run!!";
    When it doesn't work, try running the command printed to the screen, and debug that statement.

      this outputs cant run!!

        It should also output what the command was, and you should be able to look at that command and see what's wrong with it. We can't perform the debugging steps for you.


        It should output something more.

        Anyway, a better snippet for debugging:

        use Cwd; my $cmd = "perl $manuf $series $model $url $kb_color_style_nam +e $kb_color_image_url $kb_color_image_id"; print "cmd is $cmd\n"; printf "running at %s\n", getcwd; system($cmd) == 0 or die "cant run!!";

        What does that output?

Re: system command with arguments Error
by karlgoethebier (Monsignor) on Jan 07, 2013 at 18:15 UTC

    ...but why are you calling perl via system?

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      then how ?

        I assume you mean "how else"?

        Update: This was a serious question...

        Regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1012071]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-08-16 12:43 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (167 votes). Check out past polls.