Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I run an external program?
    primarykey
    data
    text
    <p>I'm on Linux mint 12.</p> <p>I want to run a program <code>usr/share/application/firefox</code> and then pass a string anywhere. I haven't found a solution for Linux but from what I've seen so far, there are many theories for Windows.</p> <pre><code>size_t ExecuteProcess(std::wstring FullPathToExe, std::wstring Parameters, size_t SecondsToWait) { size_t iMyCounter = 0, iReturnVal = 0, iPos = 0; DWORD dwExitCode = 0; std::wstring sTempStr = L""; /* - NOTE - You should check here to see if the exe even exists */ /* Add a space to the beginning of the Parameters */ if (Parameters.size() != 0) { if (Parameters[0] != L' ') { Parameters.insert(0,L" "); } } /* The first parameter needs to be the exe itself */ sTempStr = FullPathToExe; iPos = sTempStr.find_last_of(L"\\"); sTempStr.erase(0, iPos +1); Parameters = sTempStr.append(Parameters); /* CreateProcessW can modify Parameters thus we allocate needed memory */ wchar_t * pwszParam = new wchar_t[Parameters.size() + 1]; if (pwszParam == 0) { return 1; } const wchar_t* pchrTemp = Parameters.c_str(); wcscpy_s(pwszParam, Parameters.size() + 1, pchrTemp); /* CreateProcess API initialization */ STARTUPINFOW siStartupInfo; PROCESS_INFORMATION piProcessInfo; memset(&amp;siStartupInfo, 0, sizeof(siStartupInfo)); memset(&amp;piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); if (CreateProcessW(const_cast&lt;LPCWSTR&gt;(FullPathToExe.c_str()), pwszParam, 0, 0, false, CREATE_DEFAULT_ERROR_MODE, 0, 0, &amp;siStartupInfo, &amp;piProcessInfo) != false) { /* Watch the process. */ dwExitCode = WaitForSingleObject(piProcessInfo.hProcess, (SecondsToWait * 1000)); } else { /* CreateProcess failed */ iReturnVal = GetLastError(); } /* Free memory */ delete[]pwszParam; pwszParam = 0; /* Release handles */ CloseHandle(piProcessInfo.hProcess); CloseHandle(piProcessInfo.hThread); return iReturnVal; } </code></pre> <p>You can see many theories <a href="http://goffconcepts.com/techarticles/development/cpp/createprocess.html" rel="nofollow">here</a> the first answer describes how to get it done for Linux with C, I want to do it with C++, I've been googling for hours and i saw many <em>theories</em>. This subject appears to have more theories than quantum physics <code>:)</code></p> <p>I am a Python guy, because I like simplicity, so please give a simple code that would work on 32 and 64 bit if possible. </p> <p>I would like to do something like if <code>usr/share/application/firefox</code> is available, run it, else run <code>usr/share/application/googlechrome</code></p> <p>And would you please tell me why can't the same code run on Mac and Windows?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload