Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Has anyone seen perl losing arguments?

by ted.byers (Monk)
on Sep 28, 2011 at 18:58 UTC ( #928389=perlquestion: print w/replies, xml ) Need Help??
ted.byers has asked for the wisdom of the Perl Monks concerning the following question:

It is hard to imagine how one can get this wrong, but the following is giving me grief on one machine (and only that one out of the several that I use).

print "$ARGV[0]\n\t$ARGV[1]\n\t\t$ARGV[2]\n";

This is obvious and well documented, and something I have used for years without problems. However, on a new server (hosted in the cloud, if that matters), it is failing in a manneer that is a show-stopper. The buld of Activestate Perl is:

This is perl 5, version 14, subversion 1 (v5.14.1) built for MSWin32-x64-multi-thread

The problem is that with this particular machine, perl scripts invoked as:

system(" \"$now_string\""); system(" \"$now_string\" $start_date $end_date 1>Ma 2>");

loses the arguments. The above lines of code are the last in a driver script, and intermittently, the above lines of code behave as if the following had been executed instead:

system(""); system("");

It doesn't matter whether I am executing these programs using back ticks or using system, the behaviour is the same, but on this new machine, it happens about 80% of the time, and never on the other machines I use. That, especially, has me baffled.

Has anyne else seen this? If so, what is the fix? If not, does anyone have any ideas on how best to fix this?


I appreciate any help I can get


Replies are listed 'Best First'.
Re: Has anyone seen perl losing arguments?
by ikegami (Pope) on Sep 28, 2011 at 20:17 UTC

    Your file association is broken. Specifically, the "%*" is missing in your association.

    >assoc .pl .pl=Perl >ftype Perl Perl="C:\...\bin\perl.exe" "%1" %*

    Either fix the association using ftype, or don't rely on the extension.

    system("perl \"$now_string\"");

      No, the file association is OK. Files with a pl extension are associated with perl. Execution of my driver scripts relies on that.

        What does one have to do with the other?

        What's the output of

        >assoc .pl .pl=Perl ---- \ \ | v ---- >ftype Perl ???
Re: Has anyone seen perl losing arguments?
by MidLifeXis (Monsignor) on Sep 28, 2011 at 19:03 UTC

    You may find it helpful to print out the values of $now_string, $start_date, and $end_date.


      Oh, I printed everything;$now_string,$start_date and $end_date. Especially when debuggin the programs, I print out everything used as input to a function, command line arguments, &c. If I assign the comand to be executed to a variable, and print that variable before executing it via back ticks or 'system', I see what is supposed to be there, but that has no effect ont he behaviour. On my other machines, it all works as expected. On this server in the cloud, it is causing problems.

        Ok, and what were the results? What I see in your post is that the results are undef. Perhaps it would also be useful to print the argument, as a whole, that is passed to system.


Re: Has anyone seen perl losing arguments?
by Anonymous Monk on Sep 28, 2011 at 20:21 UTC

    Add this:

    system('perl -e "print qq[ARGV: @ARGV\n]" a b c');

    Do these arguments disappear also?

      No, those arguments don't disappear.

Re: Has anyone seen perl losing arguments?
by pvaldes (Chaplain) on Sep 29, 2011 at 09:29 UTC

    mmmh... this line...

    system(" \"$now_string\"");

    probably I'm not understanding the question but...

    1-Where is the "verb" for this line? No action here.

    2-Why do you need to put the first arg to the subordinate perl script inside ""?

    3-... And what args do you expect to be passed to the perl script called by the main script?

    I suggest you to rewrite the system line avoiding to be ambiguous, like this:

    system ("VERB", "ARG1", "ARG2", ...); i.e. adjust to your needs and try:

    system ("perl", "", "\"$now_string"\"");

    If you can, avoid also to call \"ARG1\". Wrap ARG in "" directly inside

      Invoking this way relies on the association of perl with .pl, and has worked on all the other flavours of Windows I have used (I had left that call as it was for years, because up until now, it has worked - and if it ain't broke, don't fix it). $now_string is wrapped in quotes because it has a format like "Tue Sep 20 2011 A". Failure to wrap it in quotes would have that misinterpreted as 5 arguments.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://928389]
Approved by moritz
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2018-06-18 21:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.