Note:- All command are working fine with OSCALL function in compiler VC12
with complier VC14
exe name is RemDicomNodes.exe
CMD command prompt:-
RemDicomNodes 5 6 1 2 3 10 8 9
RemDicomNodes.exe 1 A
RemDicomNodes 2 B B 0 localhost 1 "BE" 104 3 1 7 7 60 0 "" 2 0 0 0 0 "" 3 0 0 0 0 "" 0 6 1 2 3 10 8 9 0 0 0 0 NoConversion 0 0 0 0 1 0 0 1 BE 0 0 0 IPv4 0 0 10 0 1 0
Above all commands are working fine and showing proper output on CMD command prompt
With OSCAll function:-
RemDicomNodes 5 6 1 2 3 10 8 9
#(Working fine i am getting output in variable "outputbuffer" which i am using inside readfile API)
RemDicomNodes.exe 1 A
#(Working fine i am getting output in variable "outputbuffer" which i am using inside readfile API)
RemDicomNodes.exe 2 B B 0 localhost 1 """BE"""" " 104 3 1 7 7 60 0 " """""" " 2 0 0 0 0 " """""" " 3 0 0 0 0 " """"""" 0 6 1 2 3 10 8 9 0 0 0 0 NoConversion 0 0 0 0 1 0 0 0 AE 0 0 0 IPv4 0 0 10 0 1 0"
#Problem(that any arguments we are send but it is not working, i am not getting output in variable "outputbuffer" which i am using inside readfile API it is not printing anything )
This is the function which i am using to run my exe
What I have tried:
<pre>BOOL MagicWatchComProc::OSCall(CString i_cmd, CString& a_output, DWORD& a_exitCode, long i_timeOut)
{
STARTUPINFO aStartupInfo;
PROCESS_INFORMATION aProcessInfo;
HANDLE hReadHandle = NULL;
HANDLE hWriteHandle = NULL;
HANDLE hErrorHandle = NULL;
DWORD dwBytesRead = 0;
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
a_output = "";
DEBUG_TRACE(_T("OSCall: launching ") + i_cmd);
if (!i_cmd)
{
DEBUG_TRACE(_T("OSCall: Error: empty command\n"));
return false;
}
SetLastError(0);
FillMemory(&aStartupInfo, sizeof(aStartupInfo), 0);
aStartupInfo.cb = sizeof(aStartupInfo);
aStartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
aStartupInfo.wShowWindow = SW_HIDE;
if(!CreatePipe(&hReadHandle, &hWriteHandle, &sa, 0))
{
DEBUG_TRACE(_T("OSCall: Error: Pipe creation\n"));
return false;
}
aStartupInfo.hStdOutput = hWriteHandle;
if (!DuplicateHandle( GetCurrentProcess(), hWriteHandle, GetCurrentProcess(), &hErrorHandle, 0, TRUE, DUPLICATE_SAME_ACCESS ))
{
CloseHandle(hReadHandle);
CloseHandle(hWriteHandle);
DEBUG_TRACE(_T("OSCall: Error: duplicate handle\n"));
return false;
}
aStartupInfo.hStdError = hErrorHandle;
TCHAR l_inputCommand[2048];
_tcscpy(l_inputCommand, i_cmd);
if(!CreateProcess( NULL, l_inputCommand, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &aStartupInfo, &aProcessInfo ))
{
CloseHandle(hReadHandle);
CloseHandle(hWriteHandle);
CloseHandle(hErrorHandle);
DEBUG_TRACE(_T("OSCall: Error: could not create process\n"));
return false;
}
CloseHandle(hWriteHandle);
CloseHandle(hErrorHandle);
DWORD dwAvailableOutput = 16;
CHAR outputbuffer[18];
time_t l_time;
time_t l_startTime;
time(&l_startTime);
do
{
time(&l_time);
if( (l_time - l_startTime) > i_timeOut)
{
SetLastError(WAIT_TIMEOUT);
break;
}
if( ReadFile( hReadHandle, outputbuffer, dwAvailableOutput, &dwBytesRead, NULL ) )
{
outputbuffer[dwBytesRead] = 0;
a_output += outputbuffer;
}
}
while ( GetLastError() != ERROR_BROKEN_PIPE );
if(GetLastError() == ERROR_BROKEN_PIPE)
SetLastError(0);
CloseHandle(hReadHandle);
if( !GetLastError() )
{
return true;
}
else
{
DEBUG_TRACE(_T("OSCall: Error: cmd command failed. Error code: ")+ i2cs(GetLastError()) +_T("; ExitCode: ")+ i2cs(a_exitCode) +_T("."));
return false;
}
}
int main()
{
DWORD dwExitCode = 0;
long l_timeOut = 60000;
BOOL bRet = FALSE;
CString strInstallLmutil(_T("cmd.exe /C "));
CString strLmutilInstallFile(_T("remdicomnodes.exe"));
CString strPathLmutilInstall;
strPathLmutilInstall.Format(_T("%s\\bin\\%s"),strtemp,strLmutilInstallFile);
strInstallOption = _T("");
strInstallOption = _T(" 2 B B 0 localhost 1 \"""BE""\"" " 104 3 1 7 7 60 0 " "\"""\"" " 2 0 0 0 0 " "\"""\"" " 3 0 0 0 0 " "\"""\""" 0 6 1 2 3 10 8 9 0 0 0 0 NoConversion 0 0 0 0 1 0 0 0 AE 0 0 0 IPv4 0 0 10 0 1 0");
bRet = OSCall ( cmd, l_commandOutput, dwExitCode, l_timeOut);
SAM_TRACE1("OSCall: bRet value: :%d ",bRet);
if( bRet == FALSE )
{
SAM_TRACE0("remdicomnodes.exe execution failed \n");
}
return 0;
}