<?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[Komandozeilentool starten? (C++ Ersatz für System())]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>ich möchte von einer C++ Anwendung aus ein Kommandozeilentool starten. Unter C wäre das &quot;system(&quot;Mytool.exe -version&quot;);&quot;<br />
Der Versionsstring würde auf der Kommandozeile des aufrufenden C Programms erscheinen. So soll es auch im C++ Programm sein.</p>
<p>Was benutzt man da unter C++?<br />
ShellExecute(0, &quot;open&quot;, &quot;MyTool.exe -version&quot;, &quot;&quot;, &quot;&quot;, 0);<br />
//system(&quot;MyTool.exe -version&quot;);<br />
Der Versionsstring erscheint nicht auf der Kommandozeile. CreateProcess aus der FAQ hier hat auch nicht funktioniert.</p>
<p>Vielen Dank</p>
<p>Peter</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/175941/komandozeilentool-starten-c-ersatz-für-system</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Apr 2026 00:00:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/175941.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 Mar 2007 16:08:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Thu, 15 Mar 2007 16:08:03 GMT]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>ich möchte von einer C++ Anwendung aus ein Kommandozeilentool starten. Unter C wäre das &quot;system(&quot;Mytool.exe -version&quot;);&quot;<br />
Der Versionsstring würde auf der Kommandozeile des aufrufenden C Programms erscheinen. So soll es auch im C++ Programm sein.</p>
<p>Was benutzt man da unter C++?<br />
ShellExecute(0, &quot;open&quot;, &quot;MyTool.exe -version&quot;, &quot;&quot;, &quot;&quot;, 0);<br />
//system(&quot;MyTool.exe -version&quot;);<br />
Der Versionsstring erscheint nicht auf der Kommandozeile. CreateProcess aus der FAQ hier hat auch nicht funktioniert.</p>
<p>Vielen Dank</p>
<p>Peter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246180</guid><dc:creator><![CDATA[peterfarge]]></dc:creator><pubDate>Thu, 15 Mar 2007 16:08:03 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Thu, 15 Mar 2007 17:14:11 GMT]]></title><description><![CDATA[<p>Was heisst &quot;CreateProcess hat nicht funktioniert&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246216</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246216</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 15 Mar 2007 17:14:11 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 14:28:58 GMT]]></title><description><![CDATA[<p>Der Versionstext soll auf der Kommandozeile erscheinen. Das tut er nicht.</p>
<p>Nehmen wir als Beispiel Java:</p>
<pre><code class="language-cpp">//Die geht (Datei vorhanden):
system(&quot;java.exe -version &gt; d:\\ver.txt&quot;);

// Das nicht (Keine Datei unter D):
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {sizeof(si)};
si.wShowWindow = SW_NORMAL;
CreateProcess(&quot;java.exe -version &gt; d:\\ver.txt&quot;, &quot;&quot;, NULL, NULL, FALSE, 0, NULL, NULL, &amp;si, &amp;pi);
</code></pre>
<p>Ich vermutet das nicht die Path Variable verwendet wurde. Die Applikation um die es geht ist in der Path Variablen drin.</p>
<p>EDIT: Link zu ShellExecute();<br />
<a href="http://www.cbuilder.de/artikel/progstarten/ShellExecute.html" rel="nofollow">http://www.cbuilder.de/artikel/progstarten/ShellExecute.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246244</guid><dc:creator><![CDATA[peterfarge]]></dc:creator><pubDate>Fri, 16 Mar 2007 14:28:58 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Thu, 15 Mar 2007 18:05:52 GMT]]></title><description><![CDATA[<p>Der *erste* Parameter muss NULL sein und der zweite ein LPTSTR auf die Commandozeile mit Parameter (aber *kein* String-Literal!)</p>
<p>Siehe Beispiel in der MSDN:<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms682425.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms682425.aspx</a><br />
<a href="http://msdn2.microsoft.com/en-us/library/ms682512.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms682512.aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246253</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 15 Mar 2007 18:05:52 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 10:42:37 GMT]]></title><description><![CDATA[<p>Hallo Jochen,</p>
<p>der String Literal wäre falsch weil die Unicode Version von CreateProcess diesen String beschreiben will.</p>
<p>Aber wie kann ich CreateProcess sagen das er die Path Variable benutzen soll?<br />
Diese funktioniert ja:<br />
CreateProcess(0, &quot;C:\\Program Files\\Java\\jre1.5.0_10\\bin\\java.exe -version&quot;, 0, 0, FALSE, 0, 0, 0, &amp;si, &amp;pi);<br />
CreateProcess(&quot;C:\\Program Files\\Java\\jre1.5.0_10\\bin\\java.exe -version&quot;, 0, 0, 0, FALSE, 0, 0, 0, &amp;si, &amp;pi);</p>
<p>Ich möchte den absoluten Pfad aber nicht angeben oder herausfinden.</p>
<p>Peter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246547</guid><dc:creator><![CDATA[peterfarge_X]]></dc:creator><pubDate>Fri, 16 Mar 2007 10:42:37 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 10:50:54 GMT]]></title><description><![CDATA[<p>Gar nicht! Das machen nur die &quot;höherwertigen&quot; Funktionen! Wie z.B. ShellExecute(Ex)</p>
<p>Die Doku zu Createprocess sagt klar:<br />
<em>The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. If the file name does not contain an extension, .exe is assumed. Therefore, if the file name extension is .com, this parameter must include the .com extension.</em></p>
<p>Also warum nicht ShellExecute(Ex) verwenden?</p>
<p>BTW: Ich habe noch nie verstanden warum sich alle auf CreateProcess stürzen und die viel einfacheren Funktionen außen vor lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246555</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Fri, 16 Mar 2007 10:50:54 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 12:22:34 GMT]]></title><description><![CDATA[<p>Es wird doch die PATH Variable benutzt?</p>
<blockquote>
<p>If the file name does not contain a directory path, the system searches for the executable file in the following sequence:<br />
...<br />
6. The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.</p>
</blockquote>
<p>Quelle: <a href="http://msdn2.microsoft.com/en-us/library/ms682425.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms682425.aspx</a></p>
<pre><code class="language-cpp">HINSTANCE hInst;
// Dies geht auch nur wenn ich den vollen Pfad zu Java angebe:
hInst = ShellExecute( 0, &quot;open&quot;, &quot;java.exe -version&quot;, &quot;&quot;, &quot;&quot;, SW_SHOW);
// Java ist korrekt in $PATH eingetragen. Auf der Kommandozeile (cmd) kann ich java -version benutzen.
</code></pre>
<p>Ich habe das Problem über eine extern &quot;C&quot; Funktion und den system Aufruf gelösst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246660</guid><dc:creator><![CDATA[peterfarge_X]]></dc:creator><pubDate>Fri, 16 Mar 2007 12:22:34 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 13:04:15 GMT]]></title><description><![CDATA[<p>peterfarge_X schrieb:</p>
<blockquote>
<p>Es wird doch die PATH Variable benutzt?</p>
<blockquote>
<p>If the file name does not contain a directory path, the system searches for the executable file in the following sequence:<br />
...<br />
6. The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.</p>
</blockquote>
<p>Quelle: <a href="http://msdn2.microsoft.com/en-us/library/ms682425.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms682425.aspx</a></p>
</blockquote>
<p>Upps. Sorry! Ja Du hast recht. Ich habe die Infos zum falschen Parameter gelesen und gepostet...</p>
<p>D.h. wie haben beide Recht: <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /><br />
Wird der erste Parameter übergeben, gilt nur der und PATH wird nicht benutzt.<br />
Wird der zweite Parameter übergeben und der erste ist NULL dann wird PATH benutzt!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246675</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Fri, 16 Mar 2007 13:04:15 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 13:25:37 GMT]]></title><description><![CDATA[<p>Ist alles geklärt?<br />
Wegen der schönen Sammlung aller Varianten und Links dazu würde ich das gern in die FAQ schieben. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246701</guid><dc:creator><![CDATA[estartu]]></dc:creator><pubDate>Fri, 16 Mar 2007 13:25:37 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 13:54:50 GMT]]></title><description><![CDATA[<p>Meine funktionierende Lösung:</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
extern &quot;C&quot; void PrintJavaVersion(void) {
	system(&quot;java.exe -version&quot;);
}
</code></pre>
<p>Hier wird eine extra Konsole geöffnet und nicht in die bestehende Konsole geschrieben:</p>
<pre><code class="language-cpp">#include &lt;shellapi.h&gt;
ShellExecute( 0, &quot;open&quot;, &quot;java.exe&quot;, &quot;&quot;, &quot;&quot;, SW_SHOW);
</code></pre>
<p>Hier passiert gar nichts. Jedenfalls gibt es keine aaaa.txt:</p>
<pre><code class="language-cpp">#include &lt;shellapi.h&gt;
ShellExecute( 0, &quot;open&quot;, &quot;java.exe -version &gt; d:\\aaaa.txt&quot;, &quot;&quot;, &quot;&quot;, SW_SHOW);
</code></pre>
<p>Bei CreateProcess() war es ähnlich wie bei ShellExecute().</p>
<p>Da ich an einem Prototypen sitze reicht mir die Lösung. Später wird eine richtige GUI rangehängt, da fällt die Konsole eh weg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246730</guid><dc:creator><![CDATA[peterfarge_X]]></dc:creator><pubDate>Fri, 16 Mar 2007 13:54:50 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 16 Mar 2007 16:43:10 GMT]]></title><description><![CDATA[<p>CreateProcess wird be system auf eine ganz spezielle Weise verwendet.<br />
system, spwanl und Konsorten laden nach lpReserved2 einen Array der aktuellen Handles (d.h. auch der Konsole) und vererbt die an den neuen Prozess.</p>
<p>Wenn Du also keine neue Konsole aus einer bestehenden Konsole erzeugen willst musst Du das entsprechende Ausgabehandle vererben.</p>
<p>Schau mal in den Code von _wdospawn in der Datei!<br />
C:\Programme\Microsoft Visual Studio 8\VC\crt\src\dospawn.c</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246828</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Fri, 16 Mar 2007 16:43:10 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Thu, 17 Jan 2008 15:06:34 GMT]]></title><description><![CDATA[<p>HI,</p>
<p>ich hänge meine Frage einfach mal hier an, damit ich kein neues Thema aufmachen muss.</p>
<p>Es ist folgendes:<br />
Ich habe ein Konsolenprogramm das ich über CreateProcess() starte. Ich hab nur die exe und kann an dem Konsolenprog nichts mehr ändern!<br />
Das Programm zu starten klappt bestens. Allerdings ist es nun so, dass sich das Fenster sofort wieder schließt, wenn das Konsolenprog seine Aufgabe erledigt hat. Ich möchte aber nun, dass es offen bleit.</p>
<p>Welche Parameter muss ich wo angeben, damit sich das Fenster nicht von selbst schließt?<br />
In der Doku hab ich leider nichts gefunden.</p>
<p>Mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438478</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438478</guid><dc:creator><![CDATA[Firewall]]></dc:creator><pubDate>Thu, 17 Jan 2008 15:06:34 GMT</pubDate></item><item><title><![CDATA[Reply to Komandozeilentool starten? (C++ Ersatz für System()) on Fri, 18 Jan 2008 06:54:09 GMT]]></title><description><![CDATA[<p>Solch einen Schalter gibt es niht. Du müsstest hier eine CMD.EXE starten, die Dein Programm dann ausführt. Allerdings bleint dann die Einmgabeaufforderung offen.</p>
<p>Wenn Du das Programm so manipulierst, dass es auf eine Eingabe wartet, dann geht das natürlich auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438768</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Fri, 18 Jan 2008 06:54:09 GMT</pubDate></item></channel></rss>