#FEATURE by cg
class: OSProcess class
added:
#commandStringForProgramName:arguments:
#defaultShellPath
#possiblyQuoted:
#programName:arguments:initialEnvironment:
comment/format in: #initialize
--- a/OSProcess.st Fri Mar 02 19:11:59 2018 +0100
+++ b/OSProcess.st Sat Mar 03 10:00:39 2018 +0100
@@ -187,6 +187,15 @@
^ self new command:aCommandString directory:aStringOrFilename.
!
+commandStringForProgramName:executableFile arguments:arrayOfStrings
+ ^ String streamContents:[:s |
+ s nextPutAll:(self possiblyQuoted:executableFile asFilename pathName).
+ arrayOfStrings do:[:eachArg |
+ s nextPutAll:(self possiblyQuoted:eachArg).
+ ].
+ ]
+!
+
new
"return an initialized instance for a local process"
@@ -208,15 +217,52 @@
(OSProcess new) command:'ls'
(OSProcess onHost:'exeptn') command:'ls'
"
+!
+
+possiblyQuoted:aString
+ "should we quote or escape?"
+
+ ^ String streamContents:[:s |
+ aString do:[:ch |
+ (ch isSeparator or:[ch = $\]) ifTrue:[
+ s nextPut:$\
+ ].
+ s nextPut:ch
+ ]
+ ]
+
+ "
+ self possiblyQuoted:'foo bar'
+ self possiblyQuoted:'foo\bar'
+ "
+!
+
+programName:executableFile arguments:arrayOfStrings initialEnvironment:stringDictionary
+ "similar to command:, but with separate command and arguments"
+
+ ^ self new
+ command:(self commandStringForProgramName:executableFile arguments:arrayOfStrings);
+ environment:stringDictionary;
+ yourself
! !
!OSProcess class methodsFor:'class initialization'!
initialize
- "Backward compatibility"
+ "Backward compatibility: Win32Process is an alias for OSProcess"
+
Win32Process := self.
! !
+!OSProcess class methodsFor:'queries'!
+
+defaultShellPath
+ OperatingSystem isUNIXlike ifTrue:[
+ ^ OperatingSystem getEnvironment:'SHELL'
+ ].
+ ^ 'cmd'
+! !
+
!OSProcess methodsFor:'accessing'!
auxStream