The basics of interacting with Unix: Difference between revisions

From Cuis CookBook
Jump to navigation Jump to search
(imported material)
 
(import + hilight)
 
Line 1: Line 1:
* You absolutely need the package <code>OSProcess</code>
* You absolutely need the package <code>OSProcess</code>
* To get a reference to the process which is running your Cuis image do:
* To get a reference to the process which is running your Cuis image do:
<syntaxhighlight lang="smalltalk">

UnixProcess thisOSProcess . "=> a UnixProcess with pid 14751 "
UnixProcess thisOSProcess . "=> a UnixProcess with pid 14751 "
</syntaxhighlight>
⚫


* Then watch these interactions it should be all clear to you
* Then watch these interactions it should be all clear to you
<syntaxhighlight lang="smalltalk">
⚫
". get the current working directory of the shell when it run Cuis "
⚫
UnixProcess thisOSProcess getCwd. "=> '/home/p/prog/cuis-project' "


". get the current working directory of the shell when it run Cuis "
". get the pid of the Cuis process and his father pid "
UnixProcess thisOSProcess getCwd. "=> '/home/p/prog/cuis-project' "
UnixProcess thisOSProcess pid. "=> 14751 "
⚫
UnixProcess thisOSProcess ppid. "=> 14750 "
⚫

". get the pid of the Cuis process and his father pid "
⚫
" ------------
⚫
UnixProcess thisOSProcess pid. "=> 14751 "
⚫
from here on there are class method shortcuts that let you type less but the idea is alwys the same you are asking 'UnixProcess thisOSProcess' to give you info.
⚫
UnixProcess thisOSProcess ppid. "=> 14750 "
⚫
------------ "

⚫
" ------------
". get the environment variables of the shell who run Cuis "
from here on there are class method shortcuts that let you type less
UnixProcess env. "=> a Dictionary(#CLUTTER_IM_MODULE->'ibus' #COLORFGBG->'0;15' #COLORTERM->'truecolor' #DBUS_SESSION_BUS_ADDRESS->'unix:path=/run/user/1000/bus' .... #DESKTOP_SESSION->'plasma' #DISPLAY->':0.0' ) "
⚫
but the idea is alwys the same you are asking 'UnixProcess thisOSProcess' to

give you info.
⚫
". the program name corresponding to Cuis, which is the name of the OpenSmalltalkVM"
⚫
------------ "
⚫
UnixProcess programName . "=> './sqcogspur64linuxht/lib/squeak/5.0-202003021730/squeak' "

⚫
". get the environment variables of the shell who run Cuis "
⚫
" . the VM arguments, where there is Cuis image file and some extra parameters "
UnixProcess env. " => a Dictionary(#CLUTTER_IM_MODULE->'ibus' #COLORFGBG->'0;15'
⚫
UnixProcess arguments . "=> #('Cuis-Smalltalk-Dev/Cuis5.0-4975.image' '-d' 'Preferences veryBigFonts.') "
#COLORTERM->'truecolor' #DBUS_SESSION_BUS_ADDRESS->'unix:path=/run/user/1000/bus' ....

#DESKTOP_SESSION->'plasma' #DISPLAY->':0.0' ) "
⚫
". get stdin, stdout, stderr "
⚫
". observe that by default, as of now, stdout and stderr are both copied to Transcript but only stderr will go printed into the shell which runs Cuis. "
⚫
". the program name corresponding to Cuis, which is the name of the OpenSmalltalkVM"
UnixProcess programName .
UnixProcess stdOut nextPutAll: 'Hello world ! '.
⚫
UnixProcess stdErr nextPutAll: 'Hello world ! '.
⚫
"=> './sqcogspur64linuxht/lib/squeak/5.0-202003021730/squeak' "

</syntaxhighlight>
⚫
" . the VM arguments, where there is Cuis image file and some extra parameters "
UnixProcess arguments .
⚫
"=> #('Cuis-Smalltalk-Dev/Cuis5.0-4975.image' '-d' 'Preferences veryBigFonts.') "
⚫
". get stdin, stdout, stderr "
⚫
". observe that by default, as of now, stdout and stdrr are both copied to Transcript
but only stderr will go printed into the shell which runs Cuis. "
UnixProcess stdOut nextPutAll: 'Hello world ! '.
⚫
UnixProcess stdErr nextPutAll: 'Hello world ! '.

Latest revision as of 20:35, 12 May 2025

  • You absolutely need the package OSProcess
  • To get a reference to the process which is running your Cuis image do:
UnixProcess thisOSProcess . "=> a UnixProcess with pid 14751 "


  • Then watch these interactions it should be all clear to you
". get the current working directory of the shell when it run Cuis " 
UnixProcess thisOSProcess getCwd. "=> '/home/p/prog/cuis-project' " 

". get the pid of the Cuis process and his father pid " 
UnixProcess thisOSProcess pid.    "=> 14751 " 
UnixProcess thisOSProcess ppid.   "=> 14750 " 

" ------------ 
from here on there are class method shortcuts that let you type less but the idea is alwys the same you are asking 'UnixProcess thisOSProcess' to give you info. 
------------ " 

". get the environment variables of the shell who run Cuis " 
UnixProcess env.          "=> a Dictionary(#CLUTTER_IM_MODULE->'ibus' #COLORFGBG->'0;15' #COLORTERM->'truecolor' #DBUS_SESSION_BUS_ADDRESS->'unix:path=/run/user/1000/bus' .... #DESKTOP_SESSION->'plasma' #DISPLAY->':0.0' ) " 

". the program name corresponding to Cuis, which is the name of the OpenSmalltalkVM" 
UnixProcess programName . "=> './sqcogspur64linuxht/lib/squeak/5.0-202003021730/squeak' " 

" . the VM arguments, where there is Cuis image file and some extra parameters " 
UnixProcess arguments .   "=> #('Cuis-Smalltalk-Dev/Cuis5.0-4975.image' '-d' 'Preferences veryBigFonts.') " 

". get stdin, stdout, stderr " 
". observe that by default, as of now, stdout and stderr are both copied to Transcript but only stderr will go printed into the shell which runs Cuis. " 
UnixProcess stdOut nextPutAll: 'Hello world ! '. 
UnixProcess stdErr nextPutAll: 'Hello world ! '.