AbstractOperatingSystem.st
changeset 3927 028ca7c70ac9
parent 3901 3b435b0f4479
child 3929 97dbb77fdf79
equal deleted inserted replaced
3926:4cc33691696a 3927:028ca7c70ac9
   716      arguments in argArray (no arguments, if nil).
   716      arguments in argArray (no arguments, if nil).
   717      If successful, this method does NOT return and smalltalk is gone.
   717      If successful, this method does NOT return and smalltalk is gone.
   718      If not successful, it does return. 
   718      If not successful, it does return. 
   719      Can be used on UNIX with fork or on other systems to chain to another program."
   719      Can be used on UNIX with fork or on other systems to chain to another program."
   720 
   720 
   721     self exec:aCommandPath withArguments:argArray fork:false
   721     self exec:aCommandPath 
       
   722            withArguments:argArray 
       
   723            fileDescriptors:nil
       
   724            closeDescriptors:nil 
       
   725            fork:false 
       
   726            newPgrp:false
       
   727            inDirectory:nil
       
   728 
       
   729     "/ never reached ...
       
   730 
       
   731     "Modified: / 10.11.1998 / 20:57:02 / cg"
   722 !
   732 !
   723 
   733 
   724 exec:aCommandPath withArguments:argArray fork:doFork
   734 exec:aCommandPath withArguments:argArray fork:doFork
   725     "execute an OS command without I/O redirection.
   735     "execute an OS command without I/O redirection.
   726      The command reads its input and writes its output
   736      The command reads its input and writes its output
   727      from/to whatever terminal device ST/X was started
   737      from/to whatever terminal device ST/X was started
   728      (typically, the xterm window)"
   738      (typically, the xterm window)"
   729 
   739 
   730     ^ self exec:aCommandPath 
   740     ^ self exec:aCommandPath 
   731 	   withArguments:argArray 
   741            withArguments:argArray 
       
   742            fileDescriptors:nil
       
   743            closeDescriptors:nil 
       
   744            fork:doFork 
       
   745            newPgrp:false
       
   746            inDirectory:nil
       
   747 
       
   748     "
       
   749      |id|
       
   750 
       
   751      id := OperatingSystem fork.
       
   752      id == 0 ifTrue:[
       
   753         'I am the child'.
       
   754         OperatingSystem 
       
   755             exec:'/bin/ls' 
       
   756             withArguments:#('ls' '/tmp')
       
   757             fork:false.
       
   758         'not reached'.
       
   759      ]
       
   760     "
       
   761 
       
   762     "
       
   763      |id|
       
   764 
       
   765      id := OperatingSystem fork.
       
   766      id == 0 ifTrue:[
       
   767         'I am the child'.
       
   768         OperatingSystem 
       
   769             exec:'/bin/sh' 
       
   770             withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2')
       
   771             fork:false.
       
   772         'not reached'.
       
   773      ].
       
   774      id printNL.
       
   775      (Delay forSeconds:3.5) wait.
       
   776      'killing ...' printNL.
       
   777      OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id.
       
   778      OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
       
   779     "
       
   780 
       
   781     "Modified: / 15.7.1997 / 15:54:32 / stefan"
       
   782     "Modified: / 10.11.1998 / 20:44:59 / cg"
       
   783 !
       
   784 
       
   785 exec:aCommandPath withArguments:argArray fork:doFork inDirectory:aDirectory
       
   786     "execute an OS command without I/O redirection.
       
   787      The command reads its input and writes its output
       
   788      from/to whatever terminal device ST/X was started
       
   789      (typically, the xterm window)"
       
   790 
       
   791     ^ self exec:aCommandPath
       
   792 	   withArguments:argArray
   732 	   fileDescriptors:nil
   793 	   fileDescriptors:nil
   733 	   closeDescriptors:nil 
   794 	   closeDescriptors:nil
   734 	   fork:doFork 
   795 	   fork:doFork 
   735 	   newPgrp:false
   796 	   newPgrp:false
   736 
   797 	   inDirectory:aDirectory
   737     "
   798     "
   738      |id|
   799      |id|
   739 
   800 
   740      id := OperatingSystem fork.
   801      id := OperatingSystem fork.
   741      id == 0 ifTrue:[
   802      id == 0 ifTrue:[
   765      'killing ...' printNL.
   826      'killing ...' printNL.
   766      OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id.
   827      OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id.
   767      OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
   828      OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
   768     "
   829     "
   769 
   830 
   770     "Modified: 15.7.1997 / 15:54:32 / stefan"
       
   771 !
       
   772 
       
   773 exec:aCommandPath withArguments:argArray fork:doFork inDirectory:aDirectory
       
   774     "execute an OS command without I/O redirection.
       
   775      The command reads its input and writes its output
       
   776      from/to whatever terminal device ST/X was started
       
   777      (typically, the xterm window)"
       
   778 
       
   779     ^ self exec:aCommandPath
       
   780 	   withArguments:argArray
       
   781 	   fileDescriptors:nil
       
   782 	   closeDescriptors:nil
       
   783 	   fork:doFork 
       
   784 	   newPgrp:false
       
   785 	   inDirectory:aDirectory
       
   786     "
       
   787      |id|
       
   788 
       
   789      id := OperatingSystem fork.
       
   790      id == 0 ifTrue:[
       
   791 	'I am the child'.
       
   792 	OperatingSystem 
       
   793 	    exec:'/bin/ls' 
       
   794 	    withArguments:#('ls' '/tmp')
       
   795 	    fork:false.
       
   796 	'not reached'.
       
   797      ]
       
   798     "
       
   799 
       
   800     "
       
   801      |id|
       
   802 
       
   803      id := OperatingSystem fork.
       
   804      id == 0 ifTrue:[
       
   805 	'I am the child'.
       
   806 	OperatingSystem 
       
   807 	    exec:'/bin/sh' 
       
   808 	    withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2')
       
   809 	    fork:false.
       
   810 	'not reached'.
       
   811      ].
       
   812      id printNL.
       
   813      (Delay forSeconds:3.5) wait.
       
   814      'killing ...' printNL.
       
   815      OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id.
       
   816      OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
       
   817     "
       
   818 
       
   819     "Created: 28.1.1998 / 14:14:03 / md"
   831     "Created: 28.1.1998 / 14:14:03 / md"
   820     "Modified: 28.1.1998 / 14:14:45 / md"
   832     "Modified: 28.1.1998 / 14:14:45 / md"
   821 !
   833 !
   822 
   834 
   823 executableFileExtensions
   835 executableFileExtensions
   834      The commandString is passed to a shell for execution - see the description of
   846      The commandString is passed to a shell for execution - see the description of
   835      'sh -c' in your UNIX manual.
   847      'sh -c' in your UNIX manual.
   836      Return true if successful, false otherwise."
   848      Return true if successful, false otherwise."
   837 
   849 
   838      ^ self
   850      ^ self
   839 	executeCommand:aCommandString
   851         executeCommand:aCommandString 
   840 	onError:[:status| false]
   852         inputFrom:nil 
       
   853         outputTo:nil 
       
   854         errorTo:nil 
       
   855         inDirectory:nil
       
   856         onError:[:status| false]
   841 
   857 
   842     "unix:
   858     "unix:
   843 
   859 
   844      OperatingSystem executeCommand:'sleep 30'. 
   860      OperatingSystem executeCommand:'sleep 30'. 
   845      OperatingSystem executeCommand:'pwd'. 
   861      OperatingSystem executeCommand:'pwd'. 
   859      OperatingSystem executeCommand:'dir'
   875      OperatingSystem executeCommand:'dir'
   860      OperatingSystem executeCommand:'purge'
   876      OperatingSystem executeCommand:'purge'
   861      OperatingSystem executeCommand:'cc foo.c'
   877      OperatingSystem executeCommand:'cc foo.c'
   862     "
   878     "
   863 
   879 
   864     "Modified: 7.1.1997 / 19:29:55 / stefan"
   880     "Modified: / 7.1.1997 / 19:29:55 / stefan"
   865     "Modified: 2.5.1997 / 12:27:39 / cg"
   881     "Modified: / 10.11.1998 / 20:55:37 / cg"
       
   882 !
       
   883 
       
   884 executeCommand:aCommandString inDirectory:aDirectory
       
   885     "much like #executeCommand:, but changes the current directory
       
   886      for the command. Since this is OS specific, use this instead of
       
   887      hardwiring any 'cd ..' command strings into your applictions."
       
   888 
       
   889      ^ self
       
   890         executeCommand:aCommandString
       
   891         onError:[:status| false]
       
   892         inDirectory:aDirectory
       
   893 
       
   894     "
       
   895      OperatingSystem executeCommand:'tdump date.obj' inDirectory:'c:\winstx\stx\libbasic\objbc'. 
       
   896      OperatingSystem executeCommand:'xxdir date.obj' inDirectory:'c:\winstx\stx\libbasic\objbc'. 
       
   897      OperatingSystem executeCommand:'dir' inDirectory:'c:\'. 
       
   898      OperatingSystem executeCommand:'dir' 
       
   899     "
       
   900 
       
   901     "Modified: / 20.1.1998 / 17:03:03 / md"
       
   902     "Modified: / 10.11.1998 / 20:28:10 / cg"
       
   903     "Created: / 10.11.1998 / 21:05:45 / cg"
       
   904 !
       
   905 
       
   906 executeCommand:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream inDirectory:dirOrNil onError:aBlock
       
   907     "execute the unix command specified by the argument, aCommandString.
       
   908      The commandString is passed to a shell for execution - see the description of
       
   909      'sh -c' in your UNIX manual.
       
   910      Return true if successful.
       
   911      If not successfull, aBlock is called with an OsProcessStatus
       
   912      (containing the exit status) as argument."
       
   913 
       
   914     |pid exitStatus sema|
       
   915 
       
   916     sema := Semaphore new name:'OS command wait'.
       
   917 
       
   918     pid := Processor 
       
   919                 monitor:[
       
   920                     self 
       
   921                         startProcess:aCommandString
       
   922                         inputFrom:anExternalInStream 
       
   923                         outputTo:anExternalOutStream 
       
   924                         errorTo:anExternalErrStream
       
   925                         inDirectory:dirOrNil.
       
   926                 ] 
       
   927                 action:[:status |
       
   928                     status stillAlive ifFalse:[
       
   929                         exitStatus := status.
       
   930                         self closePid:pid.
       
   931                         sema signal
       
   932                     ].
       
   933                 ].
       
   934     pid notNil ifTrue:[
       
   935         sema wait.
       
   936     ] ifFalse:[
       
   937         exitStatus := self osProcessStatusClass processCreationFailure.
       
   938     ].
       
   939 
       
   940     exitStatus success ifFalse:[
       
   941         ^ aBlock value:exitStatus
       
   942     ].
       
   943     ^ true.
       
   944 
       
   945     "
       
   946         OperatingSystem
       
   947             executeCommand:'dir'
       
   948             inputFrom:nil
       
   949             outputTo:nil
       
   950             errorTo:nil
       
   951             onError:[:status | Transcript flash]
       
   952         
       
   953         OperatingSystem
       
   954             executeCommand:'foo'
       
   955             inputFrom:nil
       
   956             outputTo:nil
       
   957             errorTo:nil
       
   958             onError:[:status | Transcript flash]
       
   959     "
       
   960 
       
   961     "Modified: / 25.3.1997 / 11:02:02 / stefan"
       
   962     "Modified: / 28.1.1998 / 14:46:36 / md"
       
   963     "Modified: / 10.11.1998 / 20:48:08 / cg"
       
   964     "Created: / 10.11.1998 / 20:51:11 / cg"
   866 !
   965 !
   867 
   966 
   868 executeCommand:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream onError:aBlock
   967 executeCommand:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream onError:aBlock
   869     "execute the unix command specified by the argument, aCommandString.
   968     "execute the unix command specified by the argument, aCommandString.
   870      The commandString is passed to a shell for execution - see the description of
   969      The commandString is passed to a shell for execution - see the description of
   871      'sh -c' in your UNIX manual.
   970      'sh -c' in your UNIX manual.
   872      Return true if successful.
   971      Return true if successful.
   873      If not successfull, aBlock is called with an OsProcessStatus
   972      If not successfull, aBlock is called with an OsProcessStatus
   874      (containing the exit status) as argument."
   973      (containing the exit status) as argument."
   875 
   974 
   876     |pid exitStatus sema|
   975     ^ self
   877 
   976         executeCommand:aCommandString 
   878     sema := Semaphore new name:'OS command wait'.
   977         inputFrom:anExternalInStream 
   879 
   978         outputTo:anExternalOutStream 
   880     pid := Processor 
   979         errorTo:anExternalErrStream 
   881 		monitor:[
   980         inDirectory:nil
   882 		    self 
   981         onError:aBlock
   883 			startProcess:aCommandString
   982 
   884 			inputFrom:anExternalInStream 
   983     "
   885 			outputTo:anExternalOutStream 
   984         OperatingSystem
   886 			errorTo:anExternalErrStream.
   985             executeCommand:'dir'
   887 		] 
   986             inputFrom:nil
   888 		action:[:status |
   987             outputTo:nil
   889 		    status stillAlive ifFalse:[
   988             errorTo:nil
   890 			exitStatus := status.
   989             onError:[:status | Transcript flash]
   891 			self closePid:pid.
   990         
   892 			sema signal
   991         OperatingSystem
   893 		    ].
   992             executeCommand:'foo'
   894 		].
   993             inputFrom:nil
   895     pid notNil ifTrue:[
   994             outputTo:nil
   896 	sema wait.
   995             errorTo:nil
   897     ] ifFalse:[
   996             onError:[:status | Transcript flash]
   898 	exitStatus := self osProcessStatusClass processCreationFailure.
   997     "
   899     ].
   998 
   900 
   999     "Modified: / 10.11.1998 / 20:51:39 / cg"
   901     exitStatus success ifFalse:[
       
   902 	^ aBlock value:exitStatus
       
   903     ].
       
   904     ^ true.
       
   905 
       
   906     "Modified: / 25.3.1997 / 11:02:02 / stefan"
       
   907     "Modified: / 28.1.1998 / 14:46:36 / md"
       
   908     "Created: / 5.6.1998 / 19:01:57 / cg"
       
   909     "Modified: / 12.6.1998 / 16:30:08 / cg"
       
   910 !
  1000 !
   911 
  1001 
   912 executeCommand:aCommandString onError:aBlock
  1002 executeCommand:aCommandString onError:aBlock
   913     "execute the unix command specified by the argument, aCommandString.
  1003     "execute the unix command specified by the argument, aCommandString.
   914      The commandString is passed to a shell for execution - see the description of
  1004      The commandString is passed to a shell for execution - see the description of
   915      'sh -c' in your UNIX manual.
  1005      'sh -c' in your UNIX manual.
   916      Return true if successful.
  1006      Return true if successful.
   917      If not successfull, aBlock is called with an OsProcessStatus
  1007      If not successfull, aBlock is called with an OsProcessStatus
   918      (containing the exit status) as argument."
  1008      (containing the exit status) as argument."
   919 
  1009 
   920     |pid exitStatus sema|
  1010     ^ self
   921 
  1011         executeCommand:aCommandString 
   922     sema := Semaphore new name:'OS command wait'.
  1012         inputFrom:nil 
   923 
  1013         outputTo:nil 
   924     pid := Processor 
  1014         errorTo:nil 
   925 		monitor:[self startProcess:aCommandString] 
  1015         inDirectory:nil
   926 		action:[:status |
  1016         onError:aBlock
   927 			status stillAlive ifFalse:[
  1017 
   928 			    exitStatus := status.
  1018     "unix:
   929 			    self closePid:pid.
  1019 
   930 			    sema signal
  1020      OperatingSystem executeCommand:'sleep 30' onError:[]. 
   931 			].
  1021      OperatingSystem executeCommand:'pwd' onError:[:status|status inspect]. 
   932 		].
  1022      OperatingSystem executeCommand:'ls -l' onError:[]. 
   933     pid notNil ifTrue:[
  1023      OperatingSystem executeCommand:'invalidCommand' onError:[:status| status inspect]. 
   934 	sema wait.
  1024      OperatingSystem executeCommand:'rm /tmp/foofoofoofoo'onError:[:status | status inspect]. 
   935     ] ifFalse:[
  1025 
   936 	exitStatus := self osProcessStatusClass processCreationFailure.
  1026      OperatingSystem executeCommand:'dir' onError:[]. 
   937     ].
  1027      OperatingSystem executeCommand:'foo' onError:[]. 
   938 
  1028         
   939     exitStatus success ifFalse:[
       
   940 	^ aBlock value:exitStatus
       
   941     ].
       
   942     ^ true.
       
   943 
       
   944 
       
   945     "
       
   946      UnixOperatingSystem executeCommand:'sleep 30' onError:[]. 
       
   947      UnixOperatingSystem executeCommand:'pwd' onError:[:status|status inspect]. 
       
   948      UnixOperatingSystem executeCommand:'ls -l' onError:[]. 
       
   949      UnixOperatingSystem executeCommand:'invalidCommand' onError:[:status| status inspect]. 
       
   950      UnixOperatingSystem executeCommand:'rm /tmp/foofoofoofoo'onError:[:status | status inspect]. 
       
   951     "
  1029     "
   952 
  1030 
   953     "Modified: / 25.3.1997 / 11:06:43 / stefan"
  1031     "Modified: / 25.3.1997 / 11:06:43 / stefan"
   954     "Modified: / 28.1.1998 / 14:46:56 / md"
  1032     "Modified: / 28.1.1998 / 14:46:56 / md"
   955     "Created: / 5.6.1998 / 19:02:09 / cg"
  1033     "Created: / 5.6.1998 / 19:02:09 / cg"
   956     "Modified: / 12.6.1998 / 16:30:12 / cg"
  1034     "Modified: / 10.11.1998 / 20:55:02 / cg"
   957 !
  1035 !
   958 
  1036 
   959 executeCommand:aCommandString onError:aBlock inDirectory:aDirectory
  1037 executeCommand:aCommandString onError:aBlock inDirectory:aDirectory
   960     "execute the unix command specified by the argument, aCommandString.
  1038     "execute the unix command specified by the argument, aCommandString.
   961      The commandString is passed to a shell for execution - see the description of
  1039      The commandString is passed to a shell for execution - see the description of
   962      'sh -c' in your UNIX manual.
  1040      'sh -c' in your UNIX manual.
   963      Return true if successful.
  1041      Return true if successful.
   964      If not successfull, aBlock is called with an OsProcessStatus
  1042      If not successfull, aBlock is called with an OsProcessStatus
   965      (containing the exit status) as argument."
  1043      (containing the exit status) as argument."
   966 
  1044 
   967     |pid exitStatus sema|
  1045     ^ self
   968 
  1046         executeCommand:aCommandString 
   969     sema := Semaphore new name:'OS command wait'.
  1047         inputFrom:nil 
   970 
  1048         outputTo:nil 
   971     pid := Processor
  1049         errorTo:nil 
   972 		monitor:[self startProcess:aCommandString inDirectory:aDirectory]
  1050         inDirectory:aDirectory
   973 		action:[:status |
  1051         onError:aBlock
   974 			status stillAlive ifFalse:[
  1052 
   975 			    exitStatus := status.
  1053     "Modified: / 10.11.1998 / 20:54:37 / cg"
   976 			    self closePid:pid.
       
   977 			    sema signal
       
   978 			].
       
   979 		].
       
   980     pid notNil ifTrue:[
       
   981 	sema wait.
       
   982     ] ifFalse:[
       
   983 	exitStatus := self osProcessStatusClass processCreationFailure.
       
   984     ].
       
   985 
       
   986     exitStatus success ifFalse:[
       
   987 	^ aBlock value:exitStatus
       
   988     ].
       
   989     ^ true.
       
   990 
       
   991 
       
   992     "
       
   993      UnixOperatingSystem executeCommand:'sleep 30' onError:[]. 
       
   994      UnixOperatingSystem executeCommand:'pwd' onError:[:status|status inspect]. 
       
   995      UnixOperatingSystem executeCommand:'ls -l' onError:[]. 
       
   996      UnixOperatingSystem executeCommand:'invalidCommand' onError:[:status| status inspect]. 
       
   997      UnixOperatingSystem executeCommand:'rm /tmp/foofoofoofoo'onError:[:status | status inspect]. 
       
   998     "
       
   999 
       
  1000     "Created: / 5.6.1998 / 19:02:22 / cg"
       
  1001     "Modified: / 12.6.1998 / 16:30:14 / cg"
       
  1002 !
  1054 !
  1003 
  1055 
  1004 fork
  1056 fork
  1005     "fork a new (HEAVY-weight) unix process.
  1057     "fork a new (HEAVY-weight) unix process.
  1006      Not supported with MSDOS & VMS systems.
  1058      Not supported with MSDOS & VMS systems.
  1102      'sh -c' in your UNIX manual.
  1154      'sh -c' in your UNIX manual.
  1103      Return the processId if successful, nil otherwise.
  1155      Return the processId if successful, nil otherwise.
  1104      Use #waitForProcess: for synchronization and exec status return,
  1156      Use #waitForProcess: for synchronization and exec status return,
  1105      or #killProcess: to stop it."
  1157      or #killProcess: to stop it."
  1106 
  1158 
  1107     |shellAndArgs|
       
  1108 
       
  1109     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
       
  1110     ^ self
  1159     ^ self
  1111 	exec:(shellAndArgs at:1)
  1160         startProcess:aCommandString 
  1112 	withArguments:(shellAndArgs at:2)
  1161         inputFrom:nil 
  1113 	fork:true.
  1162         outputTo:nil 
       
  1163         errorTo:nil 
       
  1164         inDirectory:nil
  1114 
  1165 
  1115     "
  1166     "
  1116      |pid|
  1167      |pid|
  1117 
  1168 
  1118      pid := OperatingSystem startProcess:'sleep 2; echo 1; sleep 2; echo 2'.
  1169      pid := OperatingSystem startProcess:'sleep 2; echo 1; sleep 2; echo 2'.
  1119      (Delay forSeconds:3) wait.
  1170      (Delay forSeconds:3) wait.
  1120      OperatingSystem killProcess:pid.
  1171      OperatingSystem killProcess:pid.
  1121     "
  1172     "
  1122 
  1173     "
  1123     "Modified: 21.3.1997 / 10:04:35 / dq"
  1174      |pid|
  1124     "Modified: 2.5.1997 / 11:55:44 / cg"
  1175 
       
  1176      pid := OperatingSystem startProcess:'dir/l'.
       
  1177      (Delay forSeconds:1) wait.
       
  1178      OperatingSystem killProcess:pid.
       
  1179     "
       
  1180     "
       
  1181      |pid|
       
  1182 
       
  1183      pid := OperatingSystem 
       
  1184                 startProcess:'dir/l'
       
  1185                 inputFrom:nil
       
  1186                 outputTo:Stdout
       
  1187                 errorTo:nil
       
  1188                 inDirectory:nil.
       
  1189      (Delay forSeconds:2) wait.
       
  1190      OperatingSystem killProcess:pid.
       
  1191     "
       
  1192 
       
  1193     "Modified: / 21.3.1997 / 10:04:35 / dq"
       
  1194     "Modified: / 10.11.1998 / 21:03:50 / cg"
  1125 !
  1195 !
  1126 
  1196 
  1127 startProcess:aCommandString inDirectory:aDirectory
  1197 startProcess:aCommandString inDirectory:aDirectory
  1128     "start executing the OS command as specified by the argument, aCommandString
  1198     "start executing the OS command as specified by the argument, aCommandString
  1129      as a separate process; do not wait for the command to finish.
  1199      as a separate process; do not wait for the command to finish.
  1131      'sh -c' in your UNIX manual.
  1201      'sh -c' in your UNIX manual.
  1132      Return the processId if successful, nil otherwise.
  1202      Return the processId if successful, nil otherwise.
  1133      Use #waitForProcess: for synchronization and exec status return,
  1203      Use #waitForProcess: for synchronization and exec status return,
  1134      or #killProcess: to stop it."
  1204      or #killProcess: to stop it."
  1135 
  1205 
  1136     |shellAndArgs|
       
  1137 
       
  1138     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
       
  1139     ^ self
  1206     ^ self
  1140 	exec:(shellAndArgs at:1)
  1207         startProcess:aCommandString 
  1141 	withArguments:(shellAndArgs at:2)
  1208         inputFrom:nil 
  1142 	fork:true
  1209         outputTo:nil 
  1143 	inDirectory:aDirectory.
  1210         errorTo:nil 
       
  1211         inDirectory:aDirectory
  1144     "
  1212     "
  1145      |pid|
  1213      |pid|
  1146 
  1214 
  1147      pid := OperatingSystem startProcess:'sleep 2; echo 1; sleep 2; echo 2'.
  1215      pid := OperatingSystem startProcess:'sleep 2; echo 1; sleep 2; echo 2'.
  1148      (Delay forSeconds:3) wait.
  1216      (Delay forSeconds:3) wait.
  1149      OperatingSystem killProcess:pid.
  1217      OperatingSystem killProcess:pid.
  1150     "
  1218     "
  1151 
  1219 
  1152     "Modified: 21.3.1997 / 10:04:35 / dq"
  1220     "Modified: / 21.3.1997 / 10:04:35 / dq"
  1153     "Modified: 2.5.1997 / 11:55:44 / cg"
  1221     "Modified: / 28.1.1998 / 14:13:33 / md"
  1154     "Modified: 28.1.1998 / 14:13:33 / md"
  1222     "Modified: / 10.11.1998 / 20:59:33 / cg"
  1155 !
  1223 !
  1156 
  1224 
  1157 startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream
  1225 startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream
  1158     "start executing the OS command as specified by the argument, aCommandString
  1226     "start executing the OS command as specified by the argument, aCommandString
  1159      as a separate process; do not wait for the command to finish.
  1227      as a separate process; do not wait for the command to finish.
  1163      each may be nil.
  1231      each may be nil.
  1164      Return the processId if successful, nil otherwise.
  1232      Return the processId if successful, nil otherwise.
  1165      Use #monitorPid:action: for synchronization and exec status return,
  1233      Use #monitorPid:action: for synchronization and exec status return,
  1166      or #killProcess: to stop it."
  1234      or #killProcess: to stop it."
  1167 
  1235 
       
  1236      ^ self     
       
  1237         startProcess:aCommandString 
       
  1238         inputFrom:anExternalInStream 
       
  1239         outputTo:anExternalOutStream 
       
  1240         errorTo:anExternalErrStream 
       
  1241         inDirectory:nil
       
  1242 
       
  1243     "Modified: / 10.11.1998 / 20:59:05 / cg"
       
  1244 !
       
  1245 
       
  1246 startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream inDirectory:dir
       
  1247     "start executing the OS command as specified by the argument, aCommandString
       
  1248      as a separate process; do not wait for the command to finish.
       
  1249      The commandString is passed to a shell for execution - see the description of
       
  1250      'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
       
  1251      The command gets stdIn, stdOut and stdErr assigned from the arguments;
       
  1252      each may be nil.
       
  1253      Return the processId if successful, nil otherwise.
       
  1254      Use #monitorPid:action: for synchronization and exec status return,
       
  1255      or #killProcess: to stop it."
       
  1256 
  1168      self subclassResponsibility
  1257      self subclassResponsibility
       
  1258 
       
  1259     "Created: / 10.11.1998 / 20:58:00 / cg"
  1169 ! !
  1260 ! !
  1170 
  1261 
  1171 !AbstractOperatingSystem class methodsFor:'file access'!
  1262 !AbstractOperatingSystem class methodsFor:'file access'!
  1172 
  1263 
  1173 closeFd:anInteger
  1264 closeFd:anInteger
  3357 ! !
  3448 ! !
  3358 
  3449 
  3359 !AbstractOperatingSystem class methodsFor:'documentation'!
  3450 !AbstractOperatingSystem class methodsFor:'documentation'!
  3360 
  3451 
  3361 version
  3452 version
  3362     ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.9 1998-10-29 12:20:54 cg Exp $'
  3453     ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.10 1998-11-11 15:09:46 cg Exp $'
  3363 ! !
  3454 ! !
  3364 AbstractOperatingSystem initialize!
  3455 AbstractOperatingSystem initialize!