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:
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.
Jun 29 2011
prev sibling next sibling parent reply 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
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
parent reply Jimmy Cao <jcao219 gmail.com> writes:
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. :(
Jun 30 2011
parent reply "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
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