Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

System substitution2

by bitman (Beadle)
on Nov 20, 2002 at 14:12 UTC ( #214448=perlquestion: print w/replies, xml ) Need Help??
bitman has asked for the wisdom of the Perl Monks concerning the following question:

Re: Getting perl to recognise imbedded spaces.
Thank you all for your help thus far. LTjake said my code worked for him, so I tried it again and it does work! The code actually runs from a PL2BAT file which is running an old version of Perl 5.005 though, this doesn't work, though 5.6.1 does work. Do you know why? I may need this to work on the old version for distribution to clients.
\\PRIMARY\PERL5005\BIN\perl -x -S "%0" %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo You do not have Perl in your PATH. goto endofperl @rem '; #!perl -w $ENV{TYPE}=q("c:\scotts test\type me"); $new_debug_log=q("c:\scotts test\type me.bat"); my $rc = system("$ENV{TYPE} $new_debug_log"); __END__ :endofperl
The short-name lookup didn't appeal, thought very interesting

Replies are listed 'Best First'.
Re: System substitution2
by BrowserUk (Pope) on Nov 20, 2002 at 15:14 UTC

    I don't have perl 5.005 to verify my speculation but have you tried using the other form of the system command?

    This allows you to avoid interpolation both within Perl and by the shell which greatly simplifies the quoting you need. The following works as is under 5.6.1 and may be better under 5.005?

    #!perl -w $ENV{TYPE}='c:\scotts test\type me'; $new_debug_log='c:\scotts test\type me.bat'; my $rc = system('cmd.exe', '/c', $ENV{TYPE}, $new_debug_log );

    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Re: System substitution2
by bitman (Beadle) on Nov 20, 2002 at 15:46 UTC
    Doesn't work correctly under 5.005 either! B*gger!
    ----------------------------------------------------
    I don't have perl 5.005 to verify my speculation but have you tried using the other form of the system command? This allows you to avoid interpolation both within Perl and by the shell which greatly simplifies the quoting you need. The following works as is under 5.6.1 and may be better under 5.005?
    #!perl -w $ENV{TYPE}='c:\scotts test\type me'; $new_debug_log='c:\scotts test\type me.bat'; my $rc = system('cmd.exe', '/c', $ENV{TYPE}, $new_debug_log );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://214448]
Approved by fireartist
help
Chatterbox?
[1nickt]: Yaerox probably best to whip up an SSCCE demonstrating the failure in what you have now and post to SoPW as a question.
[Corion]: Yaerox: That's a somewhat hard problem. Encode solves the conversion part, but for guessing what encoding a file is in, that's the hard part
[Corion]: Yaerox: There is Encode::Guess, but that needs a limited set of inputs, and it also cannot handle multiple single-byte encodings
[Corion]: If you have a BOM, that's a really easy way to recognize UTF-8. Otherwise, you can try to decode a file from UTF-8, and if that works OK and doesn't crash, most likely the file was valid UTF-8

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-03-28 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (331 votes). Check out past polls.