do you need the quotes around the value?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Do you think it is a problem with escape characters then?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
What I would do is a cout of
"\"c:\\folder\\file.exe\" -parameter1:\"value1\""
Just to see if it is identical to the command you paste in the cmd window.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Just on a side note, some people would frown on system commands. The alternative is:-
click_me
But it is a little more complicated.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
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");
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
>link isn't working
Yes that is odd the content was:-
#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...
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
That would be possible, all you would be doing is writing a file with a .bat extension then calling it as a system process.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
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.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
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.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
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
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
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.
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)
system("\\dvlp\\file.exe -parameter1:value1 -parameter2:\"value2 with spaces\"");
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343