Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Has anyone seen perl losing arguments?

by ted.byers (Scribe)
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("2_CleanXMLfiles.pl \"$now_string\""); system("3a_MakeTDVfilesA.pl \"$now_string\" $start_date $end_date 1>Ma +keTDVfilesA.pl.stdout 2>MakeTDVfilesA.pl.stderr");

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("2_CleanXMLfiles.pl"); system("3a_MakeTDVfilesA.pl");

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?

Thanks

I appreciate any help I can get

Ted

Comment on Has anyone seen perl losing arguments?
Select or Download Code
Re: Has anyone seen perl losing arguments?
by MidLifeXis (Prior) 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.

    --MidLifeXis

      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.

        --MidLifeXis

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 2_CleanXMLfiles.pl \"$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 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("2_CleanXMLfiles.pl \"$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 2_CleanXMLfiles.pl 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", "2_CleanXMLfiles.pl", "\"$now_string"\"");

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

      Invoking 2_CleanXMLfiles.pl 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (16)
As of 2014-07-23 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (146 votes), past polls