karikari
karikari

Reputation: 6807

CreateProcess does not return extected value

I want to send the double quote character to my CreateProcess function. How can I do the correct way? I want to send all of this characters: "%h"

CreateProcess(L"C:\\identify -format ",L"\"%h\" trustedsnapshot.png",0,0,TRUE,NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo);

note: "identify" is an Imagemagick program.

Here is the full code:

int ExecuteExternalFile()     
{ 
SECURITY_ATTRIBUTES secattr; 
ZeroMemory(&secattr,sizeof(secattr));
secattr.nLength = sizeof(secattr);
secattr.bInheritHandle = TRUE;

HANDLE rPipe, wPipe;

//Create pipes to write and read data

CreatePipe(&rPipe,&wPipe,&secattr,0);

STARTUPINFO sInfo; 
ZeroMemory(&sInfo,sizeof(sInfo));
PROCESS_INFORMATION pInfo; 
ZeroMemory(&pInfo,sizeof(pInfo));
sInfo.cb=sizeof(sInfo);
sInfo.dwFlags=STARTF_USESTDHANDLES;
sInfo.hStdInput=NULL; 
sInfo.hStdOutput=wPipe; 
sInfo.hStdError=wPipe;

CreateProcess(L"C:\\identify",L" -format \"%h\" trustedsnapshot.png",0,0,TRUE,NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo);



CloseHandle(wPipe);

char buf[100];
DWORD reDword; 
CString m_csOutput,csTemp;
BOOL res;
do
{
  res=::ReadFile(rPipe,buf,100,&reDword,0);
  csTemp=buf;
  m_csOutput+=csTemp.Left(reDword);
}while(res);

//return m_csOutput;
float fvar; 
//fvar = atof((const char *)(LPCTSTR)(m_csOutput));  ori


//fvar=atof((LPCTSTR)m_csOutput);
fvar = _tstof(m_csOutput);

const size_t len = 256;
wchar_t buffer[len] = {};
_snwprintf(buffer, len - 1, L"%d", fvar);


MessageBox(NULL, buffer, L"test print createprocess value", MB_OK);

return fvar;
}

I need this function to return the integer value from the CreateProcess.

Upvotes: 1

Views: 943

Answers (2)

John
John

Reputation: 5635

Your problem is not the quotes. There are two problems with the way you pass parameters to CreateProcess. The first is that the command line passed in the second argument should include the name of the command (that is, it should include the value for "argv[0]"), the second is that the redirection (> testt.txt) is not handled by the CreateProcess API,. Unless c:\identify expects such arguemnts, you should not include this in the command line.

Upvotes: 1

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

The way you wrote it should work OK, or do you have any problems with it?

Upvotes: 1

Related Questions