|
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"
|
|
|
|
|
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 );
|
|
|
|
|
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\"";<br />
system( pPath );
|
|
|
|
|
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?
|
|
|
|
|
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, 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
|
|
|
|
|
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
|
|
|
|
|
IlanTal wrote: Thanks again for your generous help,
You are welcome.
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
My application is up and running at full speed.
Thanks again,
Ilan
|
|
|
|
|
IlanTal wrote: My application is up and running at full speed.
congrads
|
|
|
|
|
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.
|
|
|
|
|
Hi all,
Can anybody please tell me the difference between debug-build and release build....
thanks in advance
|
|
|
|
|
haacked.com/archive/2004/02/14/difference-between-debug-vs-release-build.aspx
http://www.codeguru.com/forum/archive/index.php/t-269905.html
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Debug and Release are for building your project with different configurations.Sometimes you use of Debug mode for debugging your project while Release mode is final build of your program for users.Debug mode contain additional data and symbols to aid debugging but Relase mode optimizations your code without extra debug data.
|
|
|
|
|
See here[^].
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
For example you can use the DEBUG mode to check manually if the code is correctly working, to do this you can use some useful macros as ASSERT () or TRACE ().
During compile of the RELEASE version that lines are jumped.
Russell
|
|
|
|
|
In debug mode, most optimizations are turned off
In debug mode, Str Library allocates more memory than strictly needed and attempts to detect buffer overwrite and stray pointer issues
In debug mode, when thread safety is also enabled, Str Library makes sure that for non-MT-marked objects, only the creator thread attempts modify operations
In debug mode, several unusual conditions that represent programming errors are checked in the code and an ASSERT-ion is thrown if a bad state is detected.
|
|
|
|