digitalmars.D - std.process.system and white spaces
- s4mmael <fake mail.com> Jun 29 2011
- Jimmy Cao <jcao219 gmail.com> Jun 29 2011
- Dejan Lekic <dejan.lekic tiscali.co.uk> Jun 29 2011
- Andrej Mitrovic <andrej.mitrovich gmail.com> Jun 29 2011
- "Nick Sabalausky" <a a.a> Jun 30 2011
- Jimmy Cao <jcao219 gmail.com> Jun 30 2011
- "Steven Schveighoffer" <schveiguy yahoo.com> Jun 30 2011
- Andrej Mitrovic <andrej.mitrovich gmail.com> Jun 30 2011
Hi all!
I'm trying to run the following command with the 'system' function:
std.process.system("\"c:\\Program Files\\some program.exe\"");
Because it's double quoted it's OK.
Now I want to redirect an output of "some program.exe" to a file:
std.process.system("\"c:\\Program Files\\some program.exe\" > c:\\filename");
And it works well too.
Then I'm trying to quote a 'filename' in case in includes a white space:
std.process.system("\"c:\\Program Files\\some program.exe\" > \"c:\\file
name\"");
but I got the following message on a standard output:
'c:\Program' is not recognized as an internal or external command, operable
program or batch file.
What is the right method to quote both paths in case of redirection to a file?
Thank you beforehand for the answer. Any advice would be greatly appreciate.
Thanks beforehand for the answer.
Jun 29 2011
--0016364c708761085b04a6da4b20
Content-Type: text/plain; charset=ISO-8859-1
Try this:
std.process.system("cmd /c \"c:\\Program Files\\some program.exe\" >
\"c:\\file name\"");
If that doesn't work then you may have to do it like this:
http://msdn.microsoft.com/en-us/library/ms682499(VS.85)
On Wed, Jun 29, 2011 at 5:58 AM, s4mmael <fake mail.com> wrote:
Hi all!
I'm trying to run the following command with the 'system' function:
std.process.system("\"c:\\Program Files\\some program.exe\"");
Because it's double quoted it's OK.
Now I want to redirect an output of "some program.exe" to a file:
std.process.system("\"c:\\Program Files\\some program.exe\" >
c:\\filename");
And it works well too.
Then I'm trying to quote a 'filename' in case in includes a white space:
std.process.system("\"c:\\Program Files\\some program.exe\" > \"c:\\file
name\"");
but I got the following message on a standard output:
'c:\Program' is not recognized as an internal or external command, operable
program or batch file.
What is the right method to quote both paths in case of redirection to a
file?
Thank you beforehand for the answer. Any advice would be greatly
appreciate.
Thanks beforehand for the answer.
--0016364c708761085b04a6da4b20
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div><div class=3D"gmail_quote"><div>Try this:</div><div><br></div><div>std=
.process.system("cmd /c \"c:\\Program Files\\some program.exe\&qu=
ot; > \"c:\\file name\"");</div></div><br><div>If that do=
esn't work then you may have to do it like this:</div>
<div><a href=3D"http://msdn.microsoft.com/en-us/library/ms682499(VS.85)">ht=
tp://msdn.microsoft.com/en-us/library/ms682499(VS.85)</a></div></div><div><=
br></div>On Wed, Jun 29, 2011 at 5:58 AM, s4mmael <span dir=3D"ltr"><<a =
href=3D"mailto:fake mail.com">fake mail.com</a>></span> wrote:<br>
<div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi all!<br>
<br>
I'm trying to run the following command with the 'system' funct=
ion:<br>
std.process.system("\"c:\\Program Files\\some program.exe\"&=
quot;);<br>
Because it's double quoted it's OK.<br>
<br>
Now I want to redirect an output of "some program.exe" to a file:=
<br>
std.process.system("\"c:\\Program Files\\some program.exe\" =
> c:\\filename");<br>
And it works well too.<br>
<br>
Then I'm trying to quote a 'filename' in case in includes a whi=
te space:<br>
std.process.system("\"c:\\Program Files\\some program.exe\" =
> \"c:\\file name\"");<br>
but I got the following message on a standard output:<br>
'c:\Program' is not recognized as an internal or external command, =
operable<br>
program or batch file.<br>
<br>
What is the right method to quote both paths in case of redirection to a fi=
le?<br>
Thank you beforehand for the answer. Any advice would be greatly appreciate=
.<br>
<br>
Thanks beforehand for the answer.</blockquote></div>
--0016364c708761085b04a6da4b20--
Jun 29 2011
I typically write such code like:
std.process.system(`C:\Program Files\some program.exe`); // WYSIWYG string
// OR:
std.process.system("C:/Program Files/some program.exe");
Jun 29 2011
You can also use: r"C:\Program Files\some program.exe"
Jun 29 2011
"s4mmael" <fake mail.com> wrote in message news:iuf0gk$1g5r$1 digitalmars.com...Hi all! I'm trying to run the following command with the 'system' function: std.process.system("\"c:\\Program Files\\some program.exe\""); Because it's double quoted it's OK. Now I want to redirect an output of "some program.exe" to a file: std.process.system("\"c:\\Program Files\\some program.exe\" > c:\\filename"); And it works well too. Then I'm trying to quote a 'filename' in case in includes a white space: std.process.system("\"c:\\Program Files\\some program.exe\" > \"c:\\file name\""); but I got the following message on a standard output: 'c:\Program' is not recognized as an internal or external command, operable program or batch file. What is the right method to quote both paths in case of redirection to a file? Thank you beforehand for the answer. Any advice would be greatly appreciate. Thanks beforehand for the answer.
Sounds like std.process.system is doing some parsing of your command and getting it wrong. :(
Jun 30 2011
--001636284ff0f993c604a6e9a9e5 Content-Type: text/plain; charset=ISO-8859-1 It's not Phobos' fault, I tried it in Python's os.system on Windows and I got the same result. It's just a quirk I guess. On Thu, Jun 30, 2011 at 3:08 AM, Nick Sabalausky <a a.a> wrote:"s4mmael" <fake mail.com> wrote in message news:iuf0gk$1g5r$1 digitalmars.com...Hi all! I'm trying to run the following command with the 'system' function: std.process.system("\"c:\\Program Files\\some program.exe\""); Because it's double quoted it's OK. Now I want to redirect an output of "some program.exe" to a file: std.process.system("\"c:\\Program Files\\some program.exe\" > c:\\filename"); And it works well too. Then I'm trying to quote a 'filename' in case in includes a white space: std.process.system("\"c:\\Program Files\\some program.exe\" > \"c:\\file name\""); but I got the following message on a standard output: 'c:\Program' is not recognized as an internal or external command, operable program or batch file. What is the right method to quote both paths in case of redirection to a file? Thank you beforehand for the answer. Any advice would be greatly appreciate. Thanks beforehand for the answer.
Sounds like std.process.system is doing some parsing of your command and getting it wrong. :(
--001636284ff0f993c604a6e9a9e5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable It's not Phobos' fault, I tried it in Python's os.system on Win= dows and I got the same result.<div>It's just a quirk I guess.<br><br><= div class=3D"gmail_quote">On Thu, Jun 30, 2011 at 3:08 AM, Nick Sabalausky = <span dir=3D"ltr"><a a.a></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">"s4mmael" <<a href=3D"mailto:fa= ke mail.com" target=3D"_blank">fake mail.com</a>> wrote in message<br> news:iuf0gk$1g5r$1 digitalmars.com...<br> <div><div></div><div>> Hi all!<br> ><br> > I'm trying to run the following command with the 'system' = function:<br> > std.process.system("\"c:\\Program Files\\some program.exe\&q= uot;");<br> > Because it's double quoted it's OK.<br> ><br> > Now I want to redirect an output of "some program.exe" to a = file:<br> > std.process.system("\"c:\\Program Files\\some program.exe\&q= uot; ><br> > c:\\filename");<br> > And it works well too.<br> ><br> > Then I'm trying to quote a 'filename' in case in includes = a white space:<br> > std.process.system("\"c:\\Program Files\\some program.exe\&q= uot; > \"c:\\file<br> > name\"");<br> > but I got the following message on a standard output:<br> > 'c:\Program' is not recognized as an internal or external comm= and,<br> > operable<br> > program or batch file.<br> ><br> > What is the right method to quote both paths in case of redirection to= a<br> > file?<br> > Thank you beforehand for the answer. Any advice would be greatly<br> > appreciate.<br> ><br> > Thanks beforehand for the answer.<br> <br> </div></div>Sounds like std.process.system is doing some parsing of your co= mmand and<br> getting it wrong. =A0:(<br> <br> <br> </blockquote></div><br></div> --001636284ff0f993c604a6e9a9e5--
Jun 30 2011
On Thu, 30 Jun 2011 04:26:36 -0400, Jimmy Cao <jcao219 gmail.com> wrote:It's not Phobos' fault, I tried it in Python's os.system on Windows and I got the same result. It's just a quirk I guess.
Windows is horrible with it's command line processing. Add on top of that, the system call to create a process takes a single string -- so there is no way to specify arguments exactly without using quotes, equivalent to Unix exec. Take a look at a proposed new version of std.process, and you can see my trial-and-error analysis of the windows command line processing engine. https://github.com/kyllingstad/phobos/blob/new-std-process/std/process.d#L469 Note, please do not try using the new version of std.process on Windows -- it requires fixes to the DMC runtime (given to Walter already). -Steve
Jun 30 2011
This is a relevant article: http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
Jun 30 2011









Jimmy Cao <jcao219 gmail.com> 