<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CreateProcess()]]></title><description><![CDATA[<p>1. ja, ich hab mir im forum alle passenden themen durchgelesen.<br />
2. ja, ich habe gegoogelt.<br />
3. ja, ich bin genervt.</p>
<p>problem:</p>
<p>eigentlich nix dickes. ich will einen batch mittels createprocess() starten. warum createprocess()? ich will den std und den err out in 2 files umleiten. deswegen kommen wir da nich drumrum.</p>
<p>das ganze soll als native methode inner halb einer jvm laufen. von daher benutz ich die wide version der methode.</p>
<p>laut msdn sollte dieser code hier funktionieren:</p>
<pre><code>LPCWSTR app = L&quot;C:\\WINNT\\system32\\cmd.exe&quot;;
	LPWSTR cmd = L&quot;/c scripts\\1.bat&quot;;
	LPCWSTR dir = L&quot;app&quot;;

	STARTUPINFO si;
	memset(&amp;si, 0, sizeof(si));
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESTDHANDLES;

	PROCESS_INFORMATION pi;
	LPSTARTUPINFOW si_w = (LPSTARTUPINFOW) &amp;si;

	bool success = CreateProcessW(app, cmd, 0, 0, TRUE, CREATE_NEW_CONSOLE, NULL, dir, si_w, &amp;pi);
</code></pre>
<p>das ganze kompiliert vernünftigt. startet auch gut. es wird auch ein prozess erzeugt allerdings führt der nicht meinen batch aus.</p>
<p>wenn ich</p>
<pre><code>LPWSTR cmd = L&quot;/c scripts\\1.bat&quot;;
</code></pre>
<p>in</p>
<pre><code>LPWSTR cmd = L&quot;/c pause&quot;;
</code></pre>
<p>änder, dann sollte der prozess gestartet werden und die shell den pause befehl durchführen. quasi sollte die shell auf ne eingabe warten und sich dann wieder beenden. tut sie aber nicht. genau wie oben wird hier einfach einen konsole geöffnet und sofort wieder geschlossen. es erscheint mir als wenn er meinen parameter 'cmd' einfach ignoriert.</p>
<p>jemand ne idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/207647/createprocess</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 14:48:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/207647.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Mar 2008 11:20:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 11:20:05 GMT]]></title><description><![CDATA[<p>1. ja, ich hab mir im forum alle passenden themen durchgelesen.<br />
2. ja, ich habe gegoogelt.<br />
3. ja, ich bin genervt.</p>
<p>problem:</p>
<p>eigentlich nix dickes. ich will einen batch mittels createprocess() starten. warum createprocess()? ich will den std und den err out in 2 files umleiten. deswegen kommen wir da nich drumrum.</p>
<p>das ganze soll als native methode inner halb einer jvm laufen. von daher benutz ich die wide version der methode.</p>
<p>laut msdn sollte dieser code hier funktionieren:</p>
<pre><code>LPCWSTR app = L&quot;C:\\WINNT\\system32\\cmd.exe&quot;;
	LPWSTR cmd = L&quot;/c scripts\\1.bat&quot;;
	LPCWSTR dir = L&quot;app&quot;;

	STARTUPINFO si;
	memset(&amp;si, 0, sizeof(si));
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESTDHANDLES;

	PROCESS_INFORMATION pi;
	LPSTARTUPINFOW si_w = (LPSTARTUPINFOW) &amp;si;

	bool success = CreateProcessW(app, cmd, 0, 0, TRUE, CREATE_NEW_CONSOLE, NULL, dir, si_w, &amp;pi);
</code></pre>
<p>das ganze kompiliert vernünftigt. startet auch gut. es wird auch ein prozess erzeugt allerdings führt der nicht meinen batch aus.</p>
<p>wenn ich</p>
<pre><code>LPWSTR cmd = L&quot;/c scripts\\1.bat&quot;;
</code></pre>
<p>in</p>
<pre><code>LPWSTR cmd = L&quot;/c pause&quot;;
</code></pre>
<p>änder, dann sollte der prozess gestartet werden und die shell den pause befehl durchführen. quasi sollte die shell auf ne eingabe warten und sich dann wieder beenden. tut sie aber nicht. genau wie oben wird hier einfach einen konsole geöffnet und sofort wieder geschlossen. es erscheint mir als wenn er meinen parameter 'cmd' einfach ignoriert.</p>
<p>jemand ne idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471360</guid><dc:creator><![CDATA[bliblablubb]]></dc:creator><pubDate>Mon, 10 Mar 2008 11:20:05 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 11:33:56 GMT]]></title><description><![CDATA[<p>Gib mal den vollständigen Pfad zur Batchdatei an. Der gestartete Prozess übernimmt AFAIK nicht dein aktuelles Arbeitsverzeichnis.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471365</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471365</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 10 Mar 2008 11:33:56 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 11:36:51 GMT]]></title><description><![CDATA[<p>Warte doch mit WaitForSingleObject auf die Process Termnierung (Handle ist in PROCESS_INFORMATION enthalten).<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471369</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471369</guid><dc:creator><![CDATA[simon.gysi]]></dc:creator><pubDate>Mon, 10 Mar 2008 11:36:51 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 11:38:02 GMT]]></title><description><![CDATA[<p>bringt nix. hat sonst jemand ne erklärung dafür, dass er das mit 'pause' nicht mal frisst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471370</guid><dc:creator><![CDATA[bliblablubb]]></dc:creator><pubDate>Mon, 10 Mar 2008 11:38:02 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 12:06:18 GMT]]></title><description><![CDATA[<p>Lass den ersten Parameter LEER (NULL) und übergib alles im zweiten!</p>
<p>Das Problem ist, dass die _meisten_ Programme davon ausgehen, dass der erste (0.) Kommandozeilen-Parameter der Name der EXE selber ist. In Deinem Fall ist es aber schon der &quot;richtige&quot; Parameter, und somit kommt das Programm nicht ganz zurecht damit...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471384</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Mon, 10 Mar 2008 12:06:18 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 12:09:11 GMT]]></title><description><![CDATA[<p>Und zum 2. Parameter von CreateProcess:</p>
<blockquote>
<p>The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1471387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471387</guid><dc:creator><![CDATA[tipp]]></dc:creator><pubDate>Mon, 10 Mar 2008 12:09:11 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 13:55:06 GMT]]></title><description><![CDATA[<p>so siehts nu aus:</p>
<pre><code>WCHAR cmd[] = L&quot;C:\\WINNT\\system32\\cmd.exe /c pause&quot;;

	LPCWSTR dir = L&quot;app&quot;;

	STARTUPINFO si;
	memset(&amp;si, 0, sizeof(si));
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESTDHANDLES;

	PROCESS_INFORMATION pi;
	LPSTARTUPINFOW si_w = (LPSTARTUPINFOW) &amp;si;

	bool success = CreateProcessW(NULL, cmd, 0, 0, TRUE, CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, NULL, dir, si_w, &amp;pi);
</code></pre>
<p>das mit 2. parameter sollte ja nu auch stimmen oder seh ich das falsch?</p>
<p>allerdings is das resultat das gleiche wie vorher auch. die konsole popt auf und geht gleich wieder zu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471455</guid><dc:creator><![CDATA[bliblablubb]]></dc:creator><pubDate>Mon, 10 Mar 2008 13:55:06 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 14:42:14 GMT]]></title><description><![CDATA[<p>bliblablubb schrieb:</p>
<blockquote>
<p>die konsole popt auf und geht gleich wieder zu.</p>
</blockquote>
<p>Schon mal daran gedacht, einfach mal auf einen Tastendruck des Users zu warten, bevor das Programm beendet wird?<br />
z.B. mit <em>getch()</em></p>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471494</guid><dc:creator><![CDATA[Mmacher]]></dc:creator><pubDate>Mon, 10 Mar 2008 14:42:14 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 14:57:16 GMT]]></title><description><![CDATA[<p>bliblablubb schrieb:</p>
<blockquote>
<p>das mit 2. parameter sollte ja nu auch stimmen oder seh ich das falsch?</p>
</blockquote>
<p>Du siehst es falsch.<br />
Verwende wcsdup um einen schreibbaren Zeiger zu bekommen! Per default legt der Compiler alle String-Literals in einen Read-Only Bereich, auch wenn Du kein &quot;const&quot; angibst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471506</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Mon, 10 Mar 2008 14:57:16 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 15:02:16 GMT]]></title><description><![CDATA[<p>Falsch, er hat es jetzt richtig! Er hat nämlich jetzt ein char-Array benutzt!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471508</guid><dc:creator><![CDATA[--------]]></dc:creator><pubDate>Mon, 10 Mar 2008 15:02:16 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Mon, 10 Mar 2008 15:08:02 GMT]]></title><description><![CDATA[<p>Ja, sorry... hatte ich übersehen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471514</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Mon, 10 Mar 2008 15:08:02 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Tue, 11 Mar 2008 08:13:41 GMT]]></title><description><![CDATA[<p>ich hab mir zu debug zwecken ne kleine exe geschrieben, die mir den übergebenen argv[] dumpt. letzte zeile in dem code ist ein getchar(). wenn ich die CreateProcessW() nun mit dieser exe aufruf, egal ob als lpApplicationName oder als erster teil von lpCommandLine oder auch beides, es ist immer das gleiche resultat: der prozess startet in einer konsole und wird sofort wieder geschlossen. pfade sind alle richtig. wenn ich nen falschen eingeb gibt mir der vaterprozess bei GetLastError() 2 zurück (FILE NOT FOUND). das tut er beim korreketen jedoch nicht. dennoch wie gesagt, keine ausgabe, unabhängig von lpCommandLine und halt die sofortige wiederschließung der konsole. jemand noch ne idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471861</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471861</guid><dc:creator><![CDATA[bliblablubb]]></dc:creator><pubDate>Tue, 11 Mar 2008 08:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to CreateProcess() on Tue, 11 Mar 2008 10:23:20 GMT]]></title><description><![CDATA[<pre><code>WCHAR cmd[] = L&quot;cmd.exe /c pause&quot;;

    STARTUPINFOW si;
    memset(&amp;si, 0, sizeof(si));
    si.cb = sizeof(si);

    PROCESS_INFORMATION pi;

    bool success = CreateProcessW(NULL, cmd, 0, 0, TRUE, CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, NULL, NULL, &amp;si, &amp;pi);
</code></pre>
<pre><code>si.dwFlags = STARTF_USESTDHANDLES;
</code></pre>
<p>bringt wohl irgendwie den entscheidenden unterschied.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1471926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1471926</guid><dc:creator><![CDATA[bliblablubb]]></dc:creator><pubDate>Tue, 11 Mar 2008 10:23:20 GMT</pubDate></item></channel></rss>