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:[ |
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. |