Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: run in-program shell script under windows using cygwin

by Laurent_R (Canon)
on Jul 30, 2014 at 17:56 UTC ( [id://1095639]=note: print w/replies, xml ) Need Help??


in reply to run in-program shell script under windows using cygwin

I was also surprised when I discovered that recently. One example. I have this silly shell script:
$ cat hello.sh #!/usr/bin/bash echo "hello world!"
Running this Perl one-liner yields no output:
$ perl -e '$command = "./hello.sh"; $out = `$command`; print $out, "\n +";'
But this:
$ perl -e '$command = "./hello.sh"; $out = `bash $command`; print $out +, "\n";' hello world!
and also this:
$ perl -e '$command = "bash ./hello.sh"; $out = `$command`; print $out +, "\n";' hello world!
both work.

Replies are listed 'Best First'.
Re^2: run in-program shell script under windows using cygwin
by AppleFritter (Vicar) on Jul 30, 2014 at 18:02 UTC

    Running this Perl one-liner yields no output:

    $ perl -e '$command = "./hello.sh"; $out = `$command`; print $out, "\n +";'

    Very strange indeed: I've just tried on Cygwin, and that's working as expected for me, producing the desired output.

      Thank you for your comment, AppleFritter, that's even more puzzling. Just in case anyone has any doubt, I can show that my shebang line in the bash script should be correct:
      $ which bash /usr/bin/bash
      It is a mystery for me at this point. Maybe something to do with the environment variables. To tell the truth, I also have a Strawberry and an ActivePerl instances installed on that MS Win 7 box, this might create problems. But the Perl version used under Cygwin is really the Cygwin Perl version:
      $ perl -v This is perl 5, version 14, subversion 4 (v5.14.4) built for cygwin-th +read-multi (with 7 registered patches, see perl -V for more detail) Copyright 1987-2013, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.

        I've also got Strawberry Perl installed on this box, but no other perls beyond these two. So far, they've never had any conflicts, as far as I was able to tell; invoking perl from a Cygwin shell always gives me Cygwin's perl, invoking it from a DOS command line alwasy gives me Strawberry.

        I've got a slightly different Perl version, though:

        $ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for cygwin-th +read-multi-64int (with 7 registered patches, see perl -V for more detail) Copyright 1987-2011, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. $

        As far as I can tell, this is because I'm using a 32-bit Cygwin (corroborated by the fact that the Cygwin installer is also offering me 5.10.1 and 5.18.2), rather than a 64-bit one. I don't know if this should make a difference, but I couldn't help but notice.

        I get

        $ perl -v

        This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2012, Larry Wall Binary build 1603 296746 provided by ActiveState http://www.ActiveState.com Built Mar 13 2013 11:29:21 Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.

Re^2: run in-program shell script under windows using cygwin
by Anonymous Monk on Jul 30, 2014 at 18:50 UTC

    I was also surprised ...

    Why?

    $ perl -V:sh sh='cmd /x /c';

    Unless your cygwin perl hash something bash in there, cmd.exe is your shell

    My *cygwin*alike* has

    $ C:\citrusperl\mingw\msys\bin\perl -V:sh sh='/bin/sh';

    So even if *my*cygwin*alike* has got /bin/sh , it won't work when calling perl from cmd.exe, only from the bash itself ... in actual cygwin that might get resolved (if cygwin perl is linked to cygwin dll) but it depends on the perl being called

      So even if *my*cygwin*alike* has got /bin/sh , it won't work when calling perl from cmd.exe

      Actually it will, same magic that actual cygwin uses to resolve it is used by the mingw/msys compiled version

      So check your paths, check your shebangs people :)

      I was surprised because I did not expect that, simply.

      Now, running your command, I get this:

      $ perl -V:sh sh='/bin/sh';
      And I have also this:
      $ which sh /usr/bin/sh
      Well, there is something that I don't get here...

        Well, there is something that I don't get here...

        Well, does /bin/sh exist? Don't know why your perl is configured with /bin/sh instead of /usr/bin/sh ... :)

      when i run the above i get

      $ which sh /usr/bin/sh

      and

      $ perl -V:sh sh='cmd /x /c';
        Well, you're running a windows perl under cygwin , cygwin isn't windows , cmd.exe don't do shell scripts without ftype/assoc

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found