<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://95.179.246.60/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Run_a_program_with_OSProcess</id>
	<title>Run a program with OSProcess - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://95.179.246.60/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Run_a_program_with_OSProcess"/>
	<link rel="alternate" type="text/html" href="http://95.179.246.60/mediawiki/index.php?title=Run_a_program_with_OSProcess&amp;action=history"/>
	<updated>2026-05-08T12:41:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>http://95.179.246.60/mediawiki/index.php?title=Run_a_program_with_OSProcess&amp;diff=174&amp;oldid=prev</id>
		<title>Nmingott: importing material</title>
		<link rel="alternate" type="text/html" href="http://95.179.246.60/mediawiki/index.php?title=Run_a_program_with_OSProcess&amp;diff=174&amp;oldid=prev"/>
		<updated>2025-05-12T20:36:23Z</updated>

		<summary type="html">&lt;p&gt;importing material&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
All the sinppets in this page require you to run&lt;br /&gt;
 Feature require: &amp;#039;OSProcess&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
=== Simple. Run a command and wait, only for the output ===&lt;br /&gt;
&lt;br /&gt;
* sync&lt;br /&gt;
* Main issue. &amp;#039;&amp;#039;&amp;#039;no exit code&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;. ---- NO - move it out from here, requires CommandShell &lt;br /&gt;
 out _ OSProcess outputOf: &amp;#039;pwd&amp;#039;. &lt;br /&gt;
 out class.                       &amp;quot;=&amp;gt; String &amp;quot;&lt;br /&gt;
 out withBlanksTrimmed.           &amp;quot;=&amp;gt; &amp;#039;/home/p/prog/cuis-project&amp;#039; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Simple. Run a command and wait, only to get the exit code ===&lt;br /&gt;
&lt;br /&gt;
* sync&lt;br /&gt;
* Main issue. &amp;#039;&amp;#039;&amp;#039;not frequently useful&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 out _ OSProcess waitForCommand: &amp;#039; sh -c &amp;quot;exit 33&amp;quot; &amp;#039;. &lt;br /&gt;
 out class.                        &amp;quot;=&amp;gt; ExternalUnixOSProcess &amp;quot;&lt;br /&gt;
 out exitCode .                    &amp;quot;=&amp;gt; 33 .   NOTE. exitCode was added on 16-oct-2021.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Run a command to get the output, no input, sync ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;. Get the current date using Linux &amp;lt;code&amp;gt;date&amp;lt;/code&amp;gt; command.&lt;br /&gt;
 d _ Delay forMilliseconds: 50.&lt;br /&gt;
 in _ nil.&lt;br /&gt;
 out _ &amp;#039;/tmp/test.out&amp;#039; asFileEntry forceWriteStream .&lt;br /&gt;
 err _  &amp;#039;/tmp/test.err&amp;#039; asFileEntry forceWriteStream .&lt;br /&gt;
 proc _ UnixProcess forkJob: &amp;#039;/usr/bin/date&amp;#039; &lt;br /&gt;
                               arguments: nil environment: nil &lt;br /&gt;
                    descriptors: {in. out. err.}.&lt;br /&gt;
 [proc runState == #complete] whileFalse: [d wait].                &lt;br /&gt;
 proc pid.&lt;br /&gt;
 oExit _ proc     exitCode .         &lt;br /&gt;
 oOut _ out contents. &lt;br /&gt;
 oErr _ err contents.             &lt;br /&gt;
 {in. out. err} do: [ :f | f ifNotNil: [ f close ] ].&lt;br /&gt;
 &amp;#039;exitCode: {1}, output: {2}&amp;#039; format: {oExit. oOut withBlanksTrimmed .}&lt;br /&gt;
 &lt;br /&gt;
 &amp;quot;=&amp;gt; &amp;#039;exitCode: 0, output: Tue 14 Sep 16:23:10 CEST 2021&amp;#039; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Run a command through the shell to get the output, no input, sync ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;. Get the first 3 lines of output of &amp;lt;code&amp;gt;ls&amp;lt;/code&amp;gt; in the current directory. That is run in &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; the&lt;br /&gt;
&lt;br /&gt;
command &amp;lt;code&amp;gt;ls -l | head -n 3&amp;lt;/code&amp;gt;.&lt;br /&gt;
 d _ Delay forMilliseconds: 50.&lt;br /&gt;
 in _ nil.&lt;br /&gt;
 out _ &amp;#039;/tmp/test.out&amp;#039; asFileEntry forceWriteStream .&lt;br /&gt;
 err _  &amp;#039;/tmp/test.err&amp;#039; asFileEntry forceWriteStream .&lt;br /&gt;
 proc _ UnixProcess forkJob: &amp;#039;/usr/bin/bash&amp;#039; &lt;br /&gt;
                               arguments: {&amp;#039;-c&amp;#039;. &amp;#039;ls -l | head -n 3&amp;#039;} &lt;br /&gt;
                           environment: nil &lt;br /&gt;
                    descriptors: {in. out. err.}.&lt;br /&gt;
 [proc runState == #complete] whileFalse: [d wait].                &lt;br /&gt;
 proc pid.&lt;br /&gt;
 oExit _ proc     exitCode .         &lt;br /&gt;
 oOut _ out contents. &lt;br /&gt;
 oErr _ err contents.             &lt;br /&gt;
 {in. out. err} do: [ :f | f ifNotNil: [ f close ] ].&lt;br /&gt;
 &amp;#039;exitCode: %d\noutput: %s&amp;#039; printf: {oExit. oOut withBlanksTrimmed } .  &lt;br /&gt;
 &amp;quot;=&amp;gt; &amp;#039;exitCode: 0&lt;br /&gt;
 output: total 3808&lt;br /&gt;
 drwxrwx---  3 p p    4096 Aug 18 12:54 AMQP&lt;br /&gt;
 drwxrwx---  3 p p    4096 Aug 18 12:54 Cairo&amp;#039; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== As before, but pass input through &amp;lt;code&amp;gt;stdin&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;. We are going to count the number of charaters of what is sent through &amp;lt;code&amp;gt;stdin&amp;lt;/code&amp;gt; via &amp;lt;code&amp;gt;wc -c&amp;lt;/code&amp;gt;.&lt;br /&gt;
 d _ Delay forMilliseconds: 50.&lt;br /&gt;
 &amp;#039;/tmp/test.in&amp;#039; asFileEntry fileContents: &amp;#039;Hello World!&amp;#039;.&lt;br /&gt;
 in _ &amp;#039;/tmp/test.in&amp;#039; asFileEntry readStream .&lt;br /&gt;
 out _ &amp;#039;/tmp/test.out&amp;#039; asFileEntry forceWriteStream .&lt;br /&gt;
 err _  &amp;#039;/tmp/test.err&amp;#039; asFileEntry forceWriteStream .&lt;br /&gt;
 proc _ UnixProcess forkJob: &amp;#039;/usr/bin/bash&amp;#039; &lt;br /&gt;
                               arguments: {&amp;#039;-c&amp;#039;. &amp;#039;wc -c&amp;#039;} &lt;br /&gt;
                           environment: nil &lt;br /&gt;
                    descriptors: {in. out. err.}.&lt;br /&gt;
 [proc runState == #complete] whileFalse: [d wait].                &lt;br /&gt;
 proc pid.&lt;br /&gt;
 oExit _ proc     exitCode .         &lt;br /&gt;
 oOut _ out contents. &lt;br /&gt;
 oErr _ err contents.             &lt;br /&gt;
 {in. out. err} do: [ :f | f ifNotNil: [ f close ] ].&lt;br /&gt;
 &amp;#039;exitCode: %d\noutput: %s&amp;#039; printf: {oExit. oOut withBlanksTrimmed } .  &lt;br /&gt;
 &lt;br /&gt;
 &amp;quot;=&amp;gt; &amp;#039;exitCode: 0&lt;br /&gt;
 output: 12&amp;#039; &amp;quot;&lt;/div&gt;</summary>
		<author><name>Nmingott</name></author>
	</entry>
</feed>