This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[OT: Perl] RE: Better solution for calling 'net use' from Cygwin Perl?


This is just a Perl, tid-bit, so disregard if you're not interested in
Perl arcana.
> -----Original Message-----
> You might also want to keep any shells from getting involved with your
> arguments; they sometimes treat '\' badly:
> 
> my $share =  "//storigen1u21/sfstest";
> $share =~ s,\\,/,g;
> system( "c:/WINDOWS/system32/net.exe", "use", "t:", $share );

Surprisingly to me, 
	system( "c:/WINDOWS/system32/net.exe use t: \"$share\"" );
doesn't invoke a shell either.

The reason is that the "system" function will break the string into words
and call exec as long as there aren't any (in Perl's opinion)
shell metacharacters (like [<>$] and I don't know what-all) in the string.

The multi-arg form is guaranteed to run exec, not a shell,
but the single-arg form is often more readable.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]