digitalmars.D - std.process.system and white spaces
- s4mmael (15/15) Jun 29 2011 Hi all!
- Jimmy Cao (6/25) Jun 29 2011 Try this:
- Dejan Lekic (4/4) Jun 29 2011 I typically write such code like:
- Andrej Mitrovic (2/2) Jun 29 2011 You can also use:
- Nick Sabalausky (4/24) Jun 30 2011 Sounds like std.process.system is doing some parsing of your command and...
- Jimmy Cao (4/33) Jun 30 2011 It's not Phobos' fault, I tried it in Python's os.system on Windows and ...
- Steven Schveighoffer (11/14) Jun 30 2011 Windows is horrible with it's command line processing. Add on top of
- Andrej Mitrovic (2/2) Jun 30 2011 This is a relevant article:
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
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
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
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
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> 