[PATCH] ssh: use shlex to parse command line

Steve Borho steve at borho.org
Fri Sep 7 13:25:33 CDT 2007

On Fri, 2007-09-07 at 10:33 -0700, Brendan Cully wrote:
> On Friday, 07 September 2007 at 10:57, Steve Borho wrote:
> > On Thu, 2007-09-06 at 20:03 -0700, Brendan Cully wrote:
> > > os.popen returns the result code, but os.popen2 does not. Probably the
> > > simplest thing to do is to use util.shellquote to produce a string for
> > > system. Something like ' '.join([util.shellquote(x) for x in args])
> > > might work? I'm not clear on what windows expects in terms of quoting
> > > though.
> > 
> > Aw crap.  os.popen3() on Windows doesn't support a list for the command
> > argument, which makes all the rest of this a moot point.  I think I need
> > to use the new subprocess module to get this to work on Windows, but
> > that's not compatible with python 2.3 AFAIK.
> > 
> > So maybe it'll be ok to include a patch for this in my installer patch
> > queue since I have control over which python it gets bundled with.
> It seems like the shellquote method I mentioned above should still
> work to produce a good string for system and popen3. Can you try it on
> windows?

util.shellquote() does create reasonable looking strings, but
os.popen3() doesn't work with them.  The error seems to indicate that
the windows ssh.exe is trying to execute 'C:\path\to\ssh" "hostname"
"hg'  as the remote command.

When I use 'hg --debug out', I can see the command line it attempted:

"C:\path\to\ssh" "hostname" "hg -R path/to/repo serve --stdio"

... which looks pretty good.  It seems os.popen3() is successfully
parsing the ssh command name, but the rest of the argument parsing
(probably a function of the windows shell) is broken.

Steve Borho (steve at borho.org)
Key fingerprint = 2D08 E7CF B624 624C DE1F  E2E4 B0C2 5292 F2C6 2C8C

More information about the Mercurial-devel mailing list