Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

system command with arguments Error

by ansh batra (Friar)
on Jan 07, 2013 at 17:34 UTC ( [id://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 Cart.pl $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 Cart.pl to a module
    • Convert the functionality of Cart.pl to a sub
    In the first case you'd have to take the time to examine what Cart.pl does and write a module for it that does the same thing. Not quite as easy as just doing
    $ cp Cart.pl Cart.pm
    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/.\/runssh_bro.pl 10.77.77.77 filename1.out/); print system (qw/.\/runssh_bro.pl 10.77.77.77 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.

    OGB

      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 Cart.pl $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.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: system command with arguments Error
by karlgoethebier (Abbot) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-03-29 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found