www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.process.system and white spaces

reply s4mmael <fake mail.com> writes:
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
next sibling parent Jimmy Cao <jcao219 gmail.com> writes:
--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(&quot;cmd /c \&quot;c:\\Program Files\\some program.exe\&qu= ot; &gt; \&quot;c:\\file name\&quot;&quot;);</div></div><br><div>If that do= esn&#39;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">&lt;<a = href=3D"mailto:fake mail.com">fake mail.com</a>&gt;</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&#39;m trying to run the following command with the &#39;system&#39; funct= ion:<br> std.process.system(&quot;\&quot;c:\\Program Files\\some program.exe\&quot;&= quot;);<br> Because it&#39;s double quoted it&#39;s OK.<br> <br> Now I want to redirect an output of &quot;some program.exe&quot; to a file:= <br> std.process.system(&quot;\&quot;c:\\Program Files\\some program.exe\&quot; = &gt; c:\\filename&quot;);<br> And it works well too.<br> <br> Then I&#39;m trying to quote a &#39;filename&#39; in case in includes a whi= te space:<br> std.process.system(&quot;\&quot;c:\\Program Files\\some program.exe\&quot; = &gt; \&quot;c:\\file name\&quot;&quot;);<br> but I got the following message on a standard output:<br> &#39;c:\Program&#39; 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
prev sibling next sibling parent Dejan Lekic <dejan.lekic tiscali.co.uk> writes:
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
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
You can also use:
r"C:\Program Files\some program.exe"
Jun 29 2011
prev sibling parent reply "Nick Sabalausky" <a a.a> writes:
"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
next sibling parent Jimmy Cao <jcao219 gmail.com> writes:
--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&#39;s not Phobos&#39; fault, I tried it in Python&#39;s os.system on Win= dows and I got the same result.<div>It&#39;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">&lt;a a.a&gt;</span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">&quot;s4mmael&quot; &lt;<a href=3D"mailto:fa= ke mail.com" target=3D"_blank">fake mail.com</a>&gt; wrote in message<br> news:iuf0gk$1g5r$1 digitalmars.com...<br> <div><div></div><div>&gt; Hi all!<br> &gt;<br> &gt; I&#39;m trying to run the following command with the &#39;system&#39; = function:<br> &gt; std.process.system(&quot;\&quot;c:\\Program Files\\some program.exe\&q= uot;&quot;);<br> &gt; Because it&#39;s double quoted it&#39;s OK.<br> &gt;<br> &gt; Now I want to redirect an output of &quot;some program.exe&quot; to a = file:<br> &gt; std.process.system(&quot;\&quot;c:\\Program Files\\some program.exe\&q= uot; &gt;<br> &gt; c:\\filename&quot;);<br> &gt; And it works well too.<br> &gt;<br> &gt; Then I&#39;m trying to quote a &#39;filename&#39; in case in includes = a white space:<br> &gt; std.process.system(&quot;\&quot;c:\\Program Files\\some program.exe\&q= uot; &gt; \&quot;c:\\file<br> &gt; name\&quot;&quot;);<br> &gt; but I got the following message on a standard output:<br> &gt; &#39;c:\Program&#39; is not recognized as an internal or external comm= and,<br> &gt; operable<br> &gt; program or batch file.<br> &gt;<br> &gt; What is the right method to quote both paths in case of redirection to= a<br> &gt; file?<br> &gt; Thank you beforehand for the answer. Any advice would be greatly<br> &gt; appreciate.<br> &gt;<br> &gt; 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
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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