Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Handling MSWin Script Output

by Orangutan (Novice)
on Sep 10, 2019 at 18:28 UTC ( [id://11105977]=note: print w/replies, xml ) Need Help??


in reply to Handling MSWin Script Output

Hello Ken, I'm not a guru or a big fan of windows, but I think I can answer question 2.

It all comes down to how windows 'luanches/executes' the script. First I want to mention that (on my windows powershell at least), it does not complain if I type:

./pm_11105937.pl
vs.
.\pm_11105937.pl
or:
perl ./pm_11105937.pl
vs.
perl .\pm_11105937.pl
and, in fact the autocomplete will complete to:
.\pm_11105937.pl
which is a subtle but I think important distinction. You might also want to look at the Unix 'source' command to see what the './' means to a bash shell. So to see how windows is executing these open the task manager next to the powershell terminal and watch whats running when you execute with:
./pm_11105937.pl
vs.
perl pm_11105937.pl
We can see that when the script is invoked with 'perl <.pl>' the perl interpreter is running in the powershell, but when invoked by itself with './<.pl>' the powershell is starting a seperate perl interpreter instance(?) to run the script.

As for question 1 though, I'm not sure, but I think there would be a way to do it with some command-line switches, for which you might find some wisdom in perldoc perlrun.

Hope I could help shed some light at least.

Replies are listed 'Best First'.
Re^2: Handling MSWin Script Output
by kcott (Archbishop) on Sep 11, 2019 at 08:39 UTC

    G'day Orangutan,

    Yes, I found out about the './ and '.\ early on when I tried just 'test_platform.pl'. There was a lot of output, which I won't post here; however, the last part of that had 'Suggestion [3,General]: The command test_platform.pl was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\test_platform.pl". ...'.

    This is pretty much the same as UNIX-like systems when '.' is not in the path. Using my Cygwin:

    $ test_platform.pl -bash: test_platform.pl: command not found $ ./test_platform.pl Platform: cygwin Executable: /home/ken/perl5/perlbrew/perls/perl-5.30.0/bin/perl

    So, from PowerShell

    perl test_platform.pl perl ./test_platform.pl perl .\test_platform.pl

    all work identically to how I described 'perl ./test_platform.pl' in the OP. And

    ./test_platform.pl .\test_platform.pl

    both work identically to how I described './test_platform.pl' in the OP.

    Anyway, what you've described regarding how the Perl interpreter is called, does make sense, and probably answers Question 2. It's a pity, because I'd prefer not to have to type 'perl' before every script name; still, it is only for a work project and won't generally affect me as I'm normally using Cygwin.

    I also noticed that you'd signed up only a fortnight ago; so please accept a belated welcome to the Monastery.

    — Ken

      Hello again, I think I learned something too, cmd indeed does run either call of the script in it's own window, only powershell opens the other window. And yeah if it's only for a minor convenience I suppose it might not be worth sinking too much time into :), but to throw some other suggestions out there, there does seem to be alot of possible ways to configure the powershell, or maybe wrap the script in a batch file or call from a batch file, and there also seems to be a 'legacy console' mode for powersell but I havent tried it.

      Thanks for the welcome.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-23 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found