#REFACTORING by stefan
class: UnixOperatingSystem
removed (already in superclass):
#exec:withArguments:environment:fileDescriptors:fork:newPgrp:inDirectory:
#startProcess:inputFrom:outputTo:errorTo:auxFrom:environment:inDirectory:
#startProcess:inputFrom:outputTo:errorTo:auxFrom:environment:inDirectory:newPgrp:showWindow:
#startProcess:inputFrom:outputTo:errorTo:auxFrom:environment:inDirectory:showWindow:
changed:
#commandAndArgsForOSCommand:
answer a 3-element array for compatibility with windows
#isDirectory:
--- a/UnixOperatingSystem.st Tue Dec 27 11:28:08 2016 +0100
+++ b/UnixOperatingSystem.st Tue Dec 27 14:02:12 2016 +0100
@@ -3184,42 +3184,6 @@
!UnixOperatingSystem class methodsFor:'executing OS commands-implementation'!
exec:aCommandPathArg withArguments:argColl environment:environmentDictionary
- fileDescriptors:fdColl fork:doFork newPgrp:newPgrp inDirectory:aDirectory
-
- ^ self
- exec:aCommandPathArg withArguments:argColl environment:environmentDictionary
- fileDescriptors:fdColl fork:doFork newPgrp:newPgrp inDirectory:aDirectory showWindow:nil
-
- "
- |id|
-
- id := OperatingSystem fork.
- id == 0 ifTrue:[
- 'I am the child'.
- OperatingSystem exec:'/bin/ls' withArguments:#('ls' '/tmp').
- 'not reached'.
- ]
- "
- "
- |id|
-
- id := OperatingSystem fork.
- id == 0 ifTrue:[
- 'I am the child'.
- OperatingSystem
- exec:'/bin/sh'
- withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2').
- 'not reached'.
- ].
- id printNL.
- (Delay forSeconds:3.5) wait.
- 'killing ...' printNL.
- OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id.
- OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
- "
-!
-
-exec:aCommandPathArg withArguments:argColl environment:environmentDictionary
fileDescriptors:fdColl fork:doFork newPgrp:newPgrp inDirectory:aDirectory showWindow:ignoredHere
"Internal lowLevel entry for combined fork & exec;
@@ -3575,224 +3539,6 @@
].
'Parent t=' print. (Timestamp now - t1) printCR.
"
-!
-
-startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
- errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
- environment:anEvironmentDictionary inDirectory:dir
-
- ^ self
- startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
- errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
- environment:anEvironmentDictionary inDirectory:dir showWindow:nil
-
- "blocking at current prio (i.e. only higher prio threads execute):
-
- OperatingSystem executeCommand:'ls -l > out'.
- OperatingSystem executeCommand:#('/bin/ls' '-l') outputTo:Transcript.
- "
-
- "non-blocking (lower prio threads continue):
-
- |in out err pid sema|
-
- in := 'out' asFilename readStream.
- out := 'out2' asFilename writeStream.
- err := 'err' asFilename writeStream.
-
- sema := Semaphore new.
- pid := OperatingSystem startProcess:'sleep 10; grep drw' inputFrom:in outputTo:out errorTo:err.
-
- The following will no longer work. monitorPid has disappeared
-
- pid notNil ifTrue:[
- Processor monitorPid:pid action:[:osStatus | sema signal ].
- ].
- in close.
- out close.
- err close.
- sema wait.
- Transcript showCR:'finished'
- "
-
- "
- |pid sema|
-
- sema := Semaphore new.
-
- Processor
- monitor:[
- pid := OperatingSystem startProcess:'(sleep 2; ls -l) > out 2>err'
- ]
- action:[:osStatus | sema signal ].
-
- sema wait.
- Transcript showCR:'finished'
- "
-
- "
- |pid sema|
-
- sema := Semaphore new.
-
- Processor
- monitor:[
- pid := OperatingSystem startProcess:'(sleep 1; echo 1; sleep 9; ls -l) > out 2>err'
- ]
- action:[:osStatus | sema signal ].
-
- Delay waitForSeconds:2.
- OperatingSystem terminateProcess:pid.
- Transcript showCR:'terminated'
- "
-
- "Modified: / 21.3.1997 / 10:04:35 / dq"
- "Modified: / 15.7.1997 / 16:03:51 / stefan"
- "Modified: / 5.6.1998 / 19:03:51 / cg"
- "Created: / 12.11.1998 / 14:39:20 / cg"
-!
-
-startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
- errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
- environment:anEvironmentDictionary inDirectory:dir newPgrp:newPgrp showWindow:ignoredHere
-
- "start executing the OS command as specified by the argument, aCommandString
- as a separate process; do not wait for the command to finish.
- If aCommandString is a String, the commandString is passed to a shell for execution
- - see the description of 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
- If aCommandString is an Array, the first element is the command to be executed,
- and the other elements are the arguments to the command. No shell is invoked in this case.
- The command gets stdIn, stdOut and stdErr assigned from the arguments;
- each may be nil.
- Return the processId if successful, nil otherwise.
- Use #monitorPid:action: for synchronization and exec status return,
- or #killProcess: to stop it."
-
- |nullStream in out err shellAndArgs rslt auxFd|
-
- aCommandString isNil ifTrue:[^ nil].
-
- (in := anExternalInStream) isNil ifTrue:[
- nullStream := Filename nullDevice readWriteStream.
- in := nullStream.
- ].
- (out := anExternalOutStream) isNil ifTrue:[
- nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
- out := nullStream.
- ].
- (err := anExternalErrStream) isNil ifTrue:[
- err := out
- ].
- anAuxiliaryStream notNil ifTrue:[
- auxFd := anAuxiliaryStream fileDescriptor
- ].
-
- shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
-
- rslt := self
- exec:(shellAndArgs at:1)
- withArguments:(shellAndArgs at:2)
- environment:anEvironmentDictionary
- fileDescriptors:(Array with:in fileDescriptor
- with:out fileDescriptor
- with:err fileDescriptor
- with:auxFd)
- fork:true
- newPgrp:newPgrp
- inDirectory:dir.
-
- nullStream notNil ifTrue:[
- nullStream close.
- ].
-
- ^ rslt
-
- "blocking at current prio (i.e. only higher prio threads execute):
-
- OperatingSystem executeCommand:'ls -l > out'.
- OperatingSystem executeCommand:#('/bin/ls' '-l') outputTo:Transcript.
- "
-
- "non-blocking (lower prio threads continue):
-
- |in out err pid sema|
-
- in := 'out' asFilename readStream.
- out := 'out2' asFilename writeStream.
- err := 'err' asFilename writeStream.
-
- sema := Semaphore new.
- pid := OperatingSystem startProcess:'sleep 10; grep drw' inputFrom:in outputTo:out errorTo:err.
-
- The following will no longer work. monitorPid has disappeared
-
- pid notNil ifTrue:[
- Processor monitorPid:pid action:[:osStatus | sema signal ].
- ].
- in close.
- out close.
- err close.
- sema wait.
- Transcript showCR:'finished'
- "
-
- "
- |pid sema|
-
- sema := Semaphore new.
-
- Processor
- monitor:[
- pid := OperatingSystem startProcess:'(sleep 2; ls -l) > out 2>err'
- ]
- action:[:osStatus | sema signal ].
-
- sema wait.
- Transcript showCR:'finished'
- "
-
- "
- |pid sema|
-
- sema := Semaphore new.
-
- Processor
- monitor:[
- pid := OperatingSystem startProcess:'(sleep 1; echo 1; sleep 9; ls -l) > out 2>err'
- ]
- action:[:osStatus | sema signal ].
-
- Delay waitForSeconds:2.
- OperatingSystem terminateProcess:pid.
- Transcript showCR:'terminated'
- "
-
- "Modified: / 21.3.1997 / 10:04:35 / dq"
- "Modified: / 15.7.1997 / 16:03:51 / stefan"
- "Modified: / 5.6.1998 / 19:03:51 / cg"
- "Created: / 12.11.1998 / 14:39:20 / cg"
-!
-
-startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
- errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
- environment:anEvironmentDictionary inDirectory:dir showWindow:ignoredHere
-
- "start executing the OS command as specified by the argument, aCommandString
- as a separate process; do not wait for the command to finish.
- If aCommandString is a String, the commandString is passed to a shell for execution
- - see the description of 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
- If aCommandString is an Array, the first element is the command to be executed,
- and the other elements are the arguments to the command. No shell is invoked in this case.
- The command gets stdIn, stdOut and stdErr assigned from the arguments;
- each may be nil.
- Return the processId if successful, nil otherwise.
- Use #monitorPid:action: for synchronization and exec status return,
- or #killProcess: to stop it."
-
- ^ self
- startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
- errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
- environment:anEvironmentDictionary inDirectory:dir newPgrp:true showWindow:ignoredHere
! !
!UnixOperatingSystem class methodsFor:'executing OS commands-queries'!
@@ -3802,18 +3548,19 @@
If aCommandString is a String, the commandString is passed to a shell for execution
- see the description of 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
If aCommandString is an Array, the first element is the command to be executed,
- and the other elements are the arguments to the command. No shell is invoked in this case."
+ and the other elements are the arguments to the command. No shell is invoked in this case.
+ The third element is nil - here for windows compatibility (showWindow in windows)"
aCommandStringOrArray isNonByteCollection ifTrue:[
- "if an array is passed, the command string has already been parsed an no shell is invoked"
- ^ Array with:aCommandStringOrArray first with:aCommandStringOrArray.
+ "if an array is passed, the command string has already been parsed an no shell is invoked"
+ ^ Array with:aCommandStringOrArray first with:aCommandStringOrArray with:nil.
].
"/
"/ '/bin/sh -c <command>'
"/
- ^ Array with:'/bin/sh' with:(Array with:'sh' with:'-c' with:aCommandStringOrArray)
+ ^ Array with:'/bin/sh' with:(Array with:'sh' with:'-c' with:aCommandStringOrArray) with:nil.
"Modified: / 20.1.1998 / 16:57:19 / md"
"Modified: / 5.6.1998 / 17:40:48 / cg"
@@ -5392,40 +5139,40 @@
%{
#ifdef __SCHTEAM__
if (encodedPathName.isStringLike()) {
- java.io.File file = new java.io.File( encodedPathName.asString() );
- int _mode;
-
- if (file.exists() && file.isDirectory()) {
- return __c__._RETURN_true();
- }
- return __c__._RETURN_false();
+ java.io.File file = new java.io.File( encodedPathName.asString() );
+ int _mode;
+
+ if (file.exists() && file.isDirectory()) {
+ return __c__._RETURN_true();
+ }
+ return __c__._RETURN_false();
}
#else
int ret;
if (__isStringLike(encodedPathName)) {
- struct stat buf;
+ struct stat buf;
# ifdef TRACE_STAT_CALLS
- printf("stat on '%s' for isDirectory\n", __stringVal(encodedPathName));
-# endif
- __BEGIN_INTERRUPTABLE__
- do {
- ret = stat((char *) __stringVal(encodedPathName), &buf);
- } while ((ret < 0) && (errno == EINTR));
- __END_INTERRUPTABLE__
- if (ret < 0) {
- @global(LastErrorNumber) = __mkSmallInteger(errno);
- RETURN ( false );
- }
- RETURN ( ((buf.st_mode & S_IFMT) == S_IFDIR) ? true : false);
+ printf("stat on '%s' for isDirectory\n", __stringVal(encodedPathName));
+# endif
+ __BEGIN_INTERRUPTABLE__
+ do {
+ ret = stat((char *) __stringVal(encodedPathName), &buf);
+ } while ((ret < 0) && (errno == EINTR));
+ __END_INTERRUPTABLE__
+ if (ret < 0) {
+ @global(LastErrorNumber) = __mkSmallInteger(errno);
+ RETURN ( false );
+ }
+ RETURN ( ((buf.st_mode & S_IFMT) == S_IFDIR) ? true : false);
}
#endif /* not SCHTEAM */
%}.
^ self primitiveFailed
"an alternative implementation would be:
- ^ (self infoOf:aPathName) type == #directory
+ ^ (self infoOf:aPathName) type == #directory
"
!