error when executing dos command

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2007
Posts: 52
Reputation: hashinclude is an unknown quantity at this point 
Solved Threads: 0
hashinclude hashinclude is offline Offline
Junior Poster in Training

Re: error when executing dos command

 
0
  #11
May 14th, 2007
Originally Posted by iamthwee View Post
Well from what you have said, i.e the cout is exactly the same as the one you pasted in the command line, I can only assume there is a problem with the system command.

Can't you create a bat file with that exact command and just call the bat file i.e

system("something.bat");
i can't because one of the parameter's value is a variable inside my program , unless there is a way (or function) to create a new bat file and write the final command line inside it and then run that bat file O_o , which if was possible , i wouldn't know how to pull that off
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: error when executing dos command

 
0
  #12
May 14th, 2007
That would be possible, all you would be doing is writing a file with a .bat extension then calling it as a system process.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 52
Reputation: hashinclude is an unknown quantity at this point 
Solved Threads: 0
hashinclude hashinclude is offline Offline
Junior Poster in Training

Re: error when executing dos command

 
0
  #13
May 14th, 2007
Originally Posted by iamthwee View Post
>link isn't working
Yes that is odd the content was:-

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4. #include <direct.h>
  5.  
  6. int main( )
  7. {
  8. chdir("C:/j2sdk1.4.2_04/bin");
  9.  
  10. STARTUPINFO si;
  11. PROCESS_INFORMATION pi;
  12. LPTSTR szCmdline=_tcsdup(TEXT("javac Saluton.java"));
  13.  
  14. ZeroMemory( &si, sizeof(si) );
  15. si.cb = sizeof(si);
  16. ZeroMemory( &pi, sizeof(pi) );
  17.  
  18. // Start the child process.
  19. if( !CreateProcess( NULL, // No module name (use command line)
  20. szCmdline, // Command line
  21. NULL, // Process handle not inheritable
  22. NULL, // Thread handle not inheritable
  23. FALSE, // Set handle inheritance to FALSE
  24. 0, // No creation flags
  25. NULL, // Use parent's environment block
  26. NULL, // Use parent's starting directory
  27. &si, // Pointer to STARTUPINFO structure
  28. &pi ) // Pointer to PROCESS_INFORMATION structure
  29. )
  30. {
  31. printf( "CreateProcess failed (%d).\n", GetLastError() );
  32. getchar();
  33. //return 0;
  34. }
  35.  
  36. // Wait until child process exits.
  37. WaitForSingleObject( pi.hProcess, INFINITE );
  38.  
  39. // Close process and thread handles.
  40. CloseHandle( pi.hProcess );
  41. CloseHandle( pi.hThread );
  42.  
  43. getchar();
  44. }

Which is an alternative to system calls on the windows platform...
i'll have to spend sometime trying to figure how this one works (i'm new at this) , it is more complicated , but thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: error when executing dos command

 
0
  #14
May 14th, 2007
Which compiler are you using?

If it's something particularly old like Turbo C 2.01, then you're probably not using cmd.exe as your command interpreter, but the rather more archaic command.com.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 52
Reputation: hashinclude is an unknown quantity at this point 
Solved Threads: 0
hashinclude hashinclude is offline Offline
Junior Poster in Training

Re: error when executing dos command

 
0
  #15
May 14th, 2007
Originally Posted by iamthwee View Post
That would be possible, all you would be doing is writing a file with a .bat extension then calling it as a system process.
i don't know how to do that with system ()
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 52
Reputation: hashinclude is an unknown quantity at this point 
Solved Threads: 0
hashinclude hashinclude is offline Offline
Junior Poster in Training

Re: error when executing dos command

 
0
  #16
May 14th, 2007
Originally Posted by Salem View Post
Which compiler are you using?

If it's something particularly old like Turbo C 2.01, then you're probably not using cmd.exe as your command interpreter, but the rather more archaic command.com.
i'm using microsoft VC++
Last edited by hashinclude; May 14th, 2007 at 4:36 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: error when executing dos command

 
0
  #17
May 14th, 2007
If you know how to write variables to a file. Then you can write your command to a bat file then just call it...

system("something.bat");

Try it. I'll leave it with you.
Last edited by iamthwee; May 14th, 2007 at 4:46 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 52
Reputation: hashinclude is an unknown quantity at this point 
Solved Threads: 0
hashinclude hashinclude is offline Offline
Junior Poster in Training

Re: error when executing dos command

 
0
  #18
May 14th, 2007
lol , thinking about , even if i could do it , having to create a bat file just to execute the command is not going to be useful for me

thanks for your help
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,412
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: error when executing dos command

 
0
  #19
May 14th, 2007
Originally Posted by hashinclude View Post
hello ,

first i want to say that im very new at c++ , i managed to create a very simple program through searching the internet , this little program involves running a certain exe file with parameters :

(e.g: "c:\folder\file.exe" -parameter1 -parameter2)

i am using the system() function to do that so my code looks something like

  1. string x;
  2. x = "\"c:\\folder\\file.exe\" -parameter1:value1 -parameter2:value2";
  3. system(x.c_str());

so it would run this command ( "c:\folder\file.exe" -parameter1:value1 -parameter2:value2 )

it works fine untill one of the parameters values must include quotes in it like this ( -parameter:"value" )

so when i type the code like this

  1. string x;
  2. x = "\"c:\\folder\\file.exe\" -parameter1:\"value1\"";
  3. system(x.c_str());



i get the error :

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.


but if i put the same command line ( with the quoted value of the parameter ) in the windows run , or in CMD , it would work fine, why do i get the error when i try to run it from the system() function ..?!!


i appereciate any help.
Check the quotes in the line you posted, there are too many of them. -- remove the quotes at the beginning of the string and after file.exe. It should be something like this (I tested it and it works)
  1. system("\\dvlp\\file.exe -parameter1:value1 -parameter2:\"value2 with spaces\"");
Last edited by Ancient Dragon; May 14th, 2007 at 5:46 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 52
Reputation: hashinclude is an unknown quantity at this point 
Solved Threads: 0
hashinclude hashinclude is offline Offline
Junior Poster in Training

Re: error when executing dos command

 
0
  #20
May 15th, 2007
thanks Ancient Dragon ,
but your solution didn't solve the problem , i still get the same error.
is there a way to run the same command line other than the system() function ?
Last edited by hashinclude; May 15th, 2007 at 3:03 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC