Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't a * in my pipe open in Perl work on Windows?

I am having this strange issue with Perl. I am trying to execute an external program from inside my Perl script and this external program takes string + wildcard as parameters. My Perl program looks like this

my $cmd_to_run = 'find-something-in-somedb myname* |' 
open(procHandle, $cmd_to_run); # I am using open because I want to 
                               # parse the output using pipes

For some weird reason, running this Perl script (under Windows) call to open function ends up with error:

'sqlselect' is not recognized as an internal or external command

I guessed that its something to do with * present in my command string and hence I removed it and now my command string looks like this

my $cmd_to_run = 'find-something-in-somedb myname|'

Now when I run my Perl script it works perfectly fine. Problem comes only when wildcard character is present.

Some points to note :

  1. I ran the same command with wildcard char, in the same cmd prompt (where i am executing this perl script) and it works perfectly fine..

  2. Same command works when I program it in C using _open function in Windows.

  3. Problem seems to be only when wildcard * is present , at least that's what I am guessing

  4. No, I haven't tried this in Unix..

Any clues???

EDIT : I found that this is something to do with ENV . The program that i am trying to run uses "sqlselect" only when "*" wild card is present in search string... Both find-something-in-somedb and sqlselect are present in same location. In which case how perl is able to find "find-in-db" and not "sqlselect"

Sorry i realize that original problem is turning out to be something else now.. Something to do with "ENV" and not with Wildcard *

like image 533
FatDaemon Avatar asked Jan 20 '26 08:01

FatDaemon


1 Answers

It is recommended to use the 3-argument form of open

open(procHandle, '-|', 'find-something-in-somedb', 'myname*');

as that bypasses the shell (which will perform * expansion).

However, on Windows, applications often perform their own quote-parsing and * expansion, so you may need

open(procHandle, '-|', 'find-something-in-somedb', '"myname*"');

or even

open(procHandle, '-|', 'find-something-in-somedb "myname*"');

as I'm not sure exactly how and when Perl hands things off to cmd.

like image 128
ephemient Avatar answered Jan 21 '26 22:01

ephemient



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!