# HG changeset patch # User Claus Gittinger # Date 1399369867 -7200 # Node ID 6f0be1e7811f5a101e50ddda00b45cd079713292 # Parent a662e916316c7299910ebc224d0c36a9c92f388a class: AbstractOperatingSystem added: #executeCommand:inputFrom:outputTo:errorTo:environment:onError: comment/format in: #decodePath: diff -r a662e916316c -r 6f0be1e7811f AbstractOperatingSystem.st --- a/AbstractOperatingSystem.st Tue May 06 11:05:46 2014 +0200 +++ b/AbstractOperatingSystem.st Tue May 06 11:51:07 2014 +0200 @@ -1457,6 +1457,72 @@ onError:aBlock ! +executeCommand:aCommandString inputFrom:anInStream outputTo:anOutStream errorTo:anErrStream environment:env onError:aBlock + "execute the unix command specified by the argument, aCommandString. + The commandString is passed to a shell for execution - see the description of + 'sh -c' in your UNIX manual. + Return true if successful, the value from aBlock if not. + If not successfull, aBlock is called with an OsProcessStatus + (containing the exit status) as argument." + + ^ self + executeCommand:aCommandString + inputFrom:anInStream + outputTo:anOutStream + errorTo:anErrStream + auxFrom:nil + environment:env + inDirectory:nil + lineWise:false + onError:aBlock + + " + OperatingSystem + executeCommand:'dir' + inputFrom:nil + outputTo:nil + errorTo:nil + onError:[:status | Transcript flash] + + OperatingSystem + executeCommand:'foo' + inputFrom:nil + outputTo:nil + errorTo:nil + onError:[:status | Transcript flash] + " + " + |outStr errStr| + + outStr := '' writeStream. + errStr := '' writeStream. + OperatingSystem + executeCommand:'ls' + inputFrom:nil + outputTo:outStr + errorTo:errStr + onError:[:status | Transcript flash]. + Transcript show:'out:'; showCR:outStr contents. + Transcript show:'err:'; showCR:errStr contents. + " + " + |outStr errStr| + + outStr := '' writeStream. + errStr := '' writeStream. + OperatingSystem + executeCommand:'ls /fooBar' + inputFrom:nil + outputTo:outStr + errorTo:errStr + onError:[:status | Transcript flash]. + Transcript show:'out:'; showCR:outStr contents. + Transcript show:'err:'; showCR:errStr contents. + " + + "Modified: / 10.11.1998 / 20:51:39 / cg" +! + executeCommand:aCommandString inputFrom:inputStreamOrNil outputTo:outStreamOrNil errorTo:errStreamOrNil inDirectory:aDirectory "much like #executeCommand:, but changes the current directory for the command. Since this is OS specific, use this instead of @@ -4249,12 +4315,12 @@ !AbstractOperatingSystem class methodsFor:'path queries'! -decodePath:encodedPathName - "decode the pathName as returned by system calls. - E.g. linux system calls return sigle byte strings only, - so the pathName has been UTF-8 decoded." - - ^ encodedPathName +decodePath:encodedPathNameOrOutputLine + "decode the encodedPathNameOrOutputLine as returned by system calls or output by system commands. + E.g. linux system calls return single byte strings only, + so pathNames have been UTF-8 encoded." + + ^ encodedPathNameOrOutputLine ! defaultPackagePath @@ -7358,11 +7424,11 @@ !AbstractOperatingSystem class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.256 2014-04-19 22:49:49 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.257 2014-05-06 09:51:07 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.256 2014-04-19 22:49:49 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.257 2014-05-06 09:51:07 cg Exp $' ! !