Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com content-class: urn:content-classes:message Subject: RE: RESOLVED: Perl system() and Cygwin MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Date: Tue, 15 Oct 2002 16:27:33 -0400 Message-ID: <7BFCE5F1EF28D64198522688F5449D5AD63A43@xchangeserver2.storigen.com> X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3 X-MS-Has-Attach: X-MS-TNEF-Correlator: From: "Scott Prive" To: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id g9FKRnA25220 > -----Original Message----- > From: Igor Pechtchanski [mailto:pechtcha AT cs DOT nyu DOT edu] > Sent: Tuesday, October 15, 2002 4:00 PM > To: Scott Prive > Cc: cygwin AT cygwin DOT com > Subject: Re: Perl system() and Cygwin > > > On Tue, 15 Oct 2002, Scott Prive wrote: > > > Hello, > > > > I'm experiencing some non-intuitive behavior when -- under > Cygwin Perl > > -- calling system commands. The FAQ alludes to "differences" between > > Cygwin and systems like Linux.. this might be another one of these > > differences, or it might be dumb-user-error. > > > > I have a solution I can live with. I just don't like not > knowing what > > breaks my other attempts. > > > > I want to do the Perl equivalent of > > net use Q: \\\\e04-3000\\foo foo /user:foo > > > > This always works in bash, running 'net' and everything else is an > > argument. This works under Cygwin /bin/bash just fine. > > > > In Perl, you can call commands like so: > > system("net use Q: \\\\e04-3000\\foo foo /user:foo"); > > This fails, with the net command returning Error 67 (resource not > > found). Unfortunately there's no way it tells me what it > THINKS it saw. > > > > This also fails: > > system("net", "use Q: \\\\e04-3000\\foo foo /user:foo"); > > > > *** This WORKS: > > system("net", "use", "Q:", "\\\\e04-3000\\foo", "foo", "/user:foo"); > > But it's *evil*. > > > > Since the above works, I try less evil-looking code: > > $cmd = "net use Q: \\\\e04-3000\\foo foo /user:foo" > > $mountcode = system (split(' ',$cmd)); > > to simulate the list that worked. This also fails. > > > > > > I've been executing code like this (all one string) all along under > > Linux & Perl. I'm assuming Perl's system() on Cygwin > executes CMD.EXE as > > a subshell (this true?) and, well, this is "one of those > differences" > > > > Any Thoughts? Thanks. > > -Scott > > Scott, > Any perl will behave like this, even the Linux one. Your > problem is the > backslashes. Since you provide the command all in one chunk, > a shell is > invoked to parse the arguments, and it obviously sees fewer > backslashes > than you provided (because some are used as escapes in perl > itself). So, > if you want to use the single-parameter system() call, you > have to escape > each backslash twice (i.e., double the number of backslashes). > I don't really know why the split doesn't work, except to > guess that it > might be interpreting the result in a scalar context... Try > assigning it > to a list first. > Igor You're right. Wrote a small shell script that echo'd out $* $@ so I could verify the translation loss. I was thinking "this worked in Linux" because I often put commands in a string, which provide some protection... but I never send \\\\ to the shell so double-escaping seemed like a non-issue. So, I have a double-escaped UNC ("ugg-lee!" :-) to mount CIFS. DB<36> system("net use Q: \\\\\\\\e04-3000\\\\foo foo /user:foo"); The command completed successfully. Thanks, Scott -- 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/