| | |
error when executing dos command
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2007
Posts: 52
Reputation:
Solved Threads: 0
•
•
•
•
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");
•
•
Join Date: May 2007
Posts: 52
Reputation:
Solved Threads: 0
•
•
•
•
>link isn't working
Yes that is odd the content was:-
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <stdio.h> #include <tchar.h> #include <direct.h> int main( ) { chdir("C:/j2sdk1.4.2_04/bin"); STARTUPINFO si; PROCESS_INFORMATION pi; LPTSTR szCmdline=_tcsdup(TEXT("javac Saluton.java")); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) szCmdline, // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { printf( "CreateProcess failed (%d).\n", GetLastError() ); getchar(); //return 0; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); getchar(); }
Which is an alternative to system calls on the windows platform...
•
•
Join Date: May 2007
Posts: 52
Reputation:
Solved Threads: 0
Last edited by hashinclude; May 14th, 2007 at 4:36 pm.
•
•
•
•
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
c++ Syntax (Toggle Plain Text)
string x; x = "\"c:\\folder\\file.exe\" -parameter1:value1 -parameter2:value2"; 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
c++ Syntax (Toggle Plain Text)
string x; x = "\"c:\\folder\\file.exe\" -parameter1:\"value1\""; 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.
C++ Syntax (Toggle Plain Text)
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Reading file path given by user
- Next Thread: Issues when placing functions from template class into seperate .cpp file [C++]
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






