system command
-
This has got to be an easy question, but I can't find a place to start. I want to give a command inside my code. The problem is when the path has a space in it like c:\Program Files\... I wanted to use system(buff) where buff = "c:\Program Files\myDir\myProg" This works fine for paths without spaces, but there is something to replace it for paths with spaces. I just can't remember what it is. Thanks, Ilan
-
This has got to be an easy question, but I can't find a place to start. I want to give a command inside my code. The problem is when the path has a space in it like c:\Program Files\... I wanted to use system(buff) where buff = "c:\Program Files\myDir\myProg" This works fine for paths without spaces, but there is something to replace it for paths with spaces. I just can't remember what it is. Thanks, Ilan
IlanTal wrote:
The problem is when the path has a space in it like c:\Program Files\...
put quote( " ) before and after the file path like.. "c:\Program Files\Windows Media Player\wmplayer.exe"
nave [OpenedFileFinder]
-
IlanTal wrote:
The problem is when the path has a space in it like c:\Program Files\...
put quote( " ) before and after the file path like.. "c:\Program Files\Windows Media Player\wmplayer.exe"
nave [OpenedFileFinder]
-
Thanks for the answer Nave. That is exactly what I tried. To my disappointment, it doesn't work for the system command. Apparently the system command is too old?
Did you try the ShellExecute() function
ShellExecute( NULL, _T("open"), _T("C:\\Program Files\\Internet Explorer\\iexplore.exe "), NULL, NULL, SW_SHOW );
nave [OpenedFileFinder]
-
Did you try the ShellExecute() function
ShellExecute( NULL, _T("open"), _T("C:\\Program Files\\Internet Explorer\\iexplore.exe "), NULL, NULL, SW_SHOW );
nave [OpenedFileFinder]
-
Thanks again Nave. No I didn't and that is exactly the answer I am looking for. I knew there was something which replaces system, but I couldn't remember what it was. I will try ShellExecute immediately. Ilan
By the time i tried the system command for path having space and it is working. Please check you specified the parameter as below
char *pPath = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\""; system( pPath );
nave [OpenedFileFinder]
-
By the time i tried the system command for path having space and it is working. Please check you specified the parameter as below
char *pPath = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\""; system( pPath );
nave [OpenedFileFinder]
Really? Unbelievable! Maybe the problem is that I'm giving an input and an output filename as parameters? If I do it at a command prompt with quotes, all works perfectly OK. If I do it by using system - on exactly the same string, it does nothing. I tried even moving the quotes to the directory with spaces, but it made no difference. c:"a b c"\dcmdjpeg C:\ic2006\dicom\kressel\study1\ctseries\view0405.dcm c:"a b c"\jpegUncompress.dcm I made a directory "a b c" just for test purposes. In this case I forgot the backslash "c:\a b c", but that isn't the problem. Could you do me a favor and see if system works if you pass parameters? For me it works fine so long as I don't both spaces in the path and spaces to separate parameters. Thanks, Ilan
-
Really? Unbelievable! Maybe the problem is that I'm giving an input and an output filename as parameters? If I do it at a command prompt with quotes, all works perfectly OK. If I do it by using system - on exactly the same string, it does nothing. I tried even moving the quotes to the directory with spaces, but it made no difference. c:"a b c"\dcmdjpeg C:\ic2006\dicom\kressel\study1\ctseries\view0405.dcm c:"a b c"\jpegUncompress.dcm I made a directory "a b c" just for test purposes. In this case I forgot the backslash "c:\a b c", but that isn't the problem. Could you do me a favor and see if system works if you pass parameters? For me it works fine so long as I don't both spaces in the path and spaces to separate parameters. Thanks, Ilan
Can you tell me which command are you trying to execute using the system?
nave [OpenedFileFinder]
-
Can you tell me which command are you trying to execute using the system?
nave [OpenedFileFinder]
It is an exe file which I received to decompress JPEG Dicom files. I'm sure the problem exists for any command which has parameters on the command line. Again it worked just fine until I tried using a path which included "Program Files". Maybe I should try to run notepad with an input file and see if notepad opens the file. I'll try something like ""c:\a b c\notepad" myfile.txt" First I'll try c:\ilan\notepad myfile.txt, since that should work.
-
This has got to be an easy question, but I can't find a place to start. I want to give a command inside my code. The problem is when the path has a space in it like c:\Program Files\... I wanted to use system(buff) where buff = "c:\Program Files\myDir\myProg" This works fine for paths without spaces, but there is something to replace it for paths with spaces. I just can't remember what it is. Thanks, Ilan
your problem is because the \ character is understood as the escapment character, so, to "output" a \, you must type
'\\'
:buff = "c:**\\Program Files\\myDir\\**myProg"
BTW, prefer avoid using the ::system() CRT function because it is not totaly safe. use it
::Shellexecute()
or::CreateProcess()
instead.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
It is an exe file which I received to decompress JPEG Dicom files. I'm sure the problem exists for any command which has parameters on the command line. Again it worked just fine until I tried using a path which included "Program Files". Maybe I should try to run notepad with an input file and see if notepad opens the file. I'll try something like ""c:\a b c\notepad" myfile.txt" First I'll try c:\ilan\notepad myfile.txt, since that should work.
IlanTal wrote:
I'll try something like ""c:\a b c\notepad" myfile.txt"
in this case you should specify like system( "notepad.exe \"C:\\a b c\\myfile.txt"" ); note that \ " are all special character, when you want to insert a quote(") in a string u have to place a \ infront of it. suppose you hard code "abcd" in the code and passed to the system, then the function will get
abcd
you have to specify like "\"abcd\"" for the system() for it to get a string like "abcd"nave [OpenedFileFinder]
-
IlanTal wrote:
I'll try something like ""c:\a b c\notepad" myfile.txt"
in this case you should specify like system( "notepad.exe \"C:\\a b c\\myfile.txt"" ); note that \ " are all special character, when you want to insert a quote(") in a string u have to place a \ infront of it. suppose you hard code "abcd" in the code and passed to the system, then the function will get
abcd
you have to specify like "\"abcd\"" for the system() for it to get a string like "abcd"nave [OpenedFileFinder]
Nave, thanks for all your kind help. It has been very useful indeed! Apparently it is a combination of system together with that particular exe I'm using. The exe has to parse the command line to get the input and output files and it has a subtle bug. All my experiments of using notepad worked fine. (I copied notepad into a b c for test purposes.) On the other hand that exe fails using the system command. If I take the buffer which I pass to system and copy it into a command box, all works fine! I think it is time to use ShellExecute as you originally suggested. The experiments have been fun, but the system command with that exe doing parsing don't seem to work. Ilan
-
IlanTal wrote:
I'll try something like ""c:\a b c\notepad" myfile.txt"
in this case you should specify like system( "notepad.exe \"C:\\a b c\\myfile.txt"" ); note that \ " are all special character, when you want to insert a quote(") in a string u have to place a \ infront of it. suppose you hard code "abcd" in the code and passed to the system, then the function will get
abcd
you have to specify like "\"abcd\"" for the system() for it to get a string like "abcd"nave [OpenedFileFinder]
Nave, I just wanted to let you know what a joy the ShellExecute is. I used c:\a b c\ as the default directory and I separated out the command from the parameters. In system it was all one big mess and the exe file got confused. With ShellExecute everything works like a charm. Thanks again for your generous help, Ilan
-
Nave, I just wanted to let you know what a joy the ShellExecute is. I used c:\a b c\ as the default directory and I separated out the command from the parameters. In system it was all one big mess and the exe file got confused. With ShellExecute everything works like a charm. Thanks again for your generous help, Ilan
-
I've run into a new problem. ShellExecute launches the program and then returns. I need the results of the program so I need to know when the program is finished. It turns out that system() returns only after the program has finished. Is there any obvious way to know the program has finished? Thanks, Ilan
-
I've run into a new problem. ShellExecute launches the program and then returns. I need the results of the program so I need to know when the program is finished. It turns out that system() returns only after the program has finished. Is there any obvious way to know the program has finished? Thanks, Ilan
in that case use the ShellExecuteEx() function. in that function you will get the handle of the new process. so after calling the ShellExecuteEx() function wait for the handle using the WaitForSingleObject() function.
nave [OpenedFileFinder]
-
in that case use the ShellExecuteEx() function. in that function you will get the handle of the new process. so after calling the ShellExecuteEx() function wait for the handle using the WaitForSingleObject() function.
nave [OpenedFileFinder]
Once again, thanks for your help. When I ran things under the debugger, I looked at the directories, saw what files there were, saw how they were created, and I was happy that everything was working. When I let it go, I realized I still had a problem. Your help has been extremely useful. Ilan
-
in that case use the ShellExecuteEx() function. in that function you will get the handle of the new process. so after calling the ShellExecuteEx() function wait for the handle using the WaitForSingleObject() function.
nave [OpenedFileFinder]
-