1464 ^ UnsupportedOperationSignal raise |
1464 ^ UnsupportedOperationSignal raise |
1465 ! |
1465 ! |
1466 |
1466 |
1467 getCommandOutputFrom:aCommand |
1467 getCommandOutputFrom:aCommand |
1468 "execute a simple command (such as hostname) and |
1468 "execute a simple command (such as hostname) and |
1469 return the commands first line of output as a string. |
1469 return the commands first line of output as a string (forget stdErr). |
1470 If the command generates multiple output lines, only the first line is returned. |
1470 If the command generates multiple output lines, only the first line is returned. |
1471 If the commands does not generate any output, an empty string is returned; |
1471 If the commands does not generate any output, an empty string is returned; |
1472 if the command fails, nil is returned." |
1472 if the command fails, nil is returned." |
1473 |
1473 |
1474 |result| |
1474 |result| |
1475 |
1475 |
1476 result := self getCommandOutputFrom:aCommand maxNumberOfLines:1. |
1476 result := self getCommandOutputFrom:aCommand maxNumberOfLines:1 errorDisposition:#discard. |
1477 result notNil ifTrue:[ |
1477 result notNil ifTrue:[ |
1478 ^ result firstIfEmpty:[''] |
1478 ^ result firstIfEmpty:[''] |
1479 ]. |
1479 ]. |
1480 ^ result |
1480 ^ result |
1481 |
1481 |
1486 OperatingSystem getCommandOutputFrom:'foo' |
1486 OperatingSystem getCommandOutputFrom:'foo' |
1487 " |
1487 " |
1488 |
1488 |
1489 ! |
1489 ! |
1490 |
1490 |
1491 getCommandOutputFrom:aCommand maxNumberOfLines:numLinesOrNil |
1491 getCommandOutputFrom:aCommand maxNumberOfLines:numLinesOrNil errorDisposition:errorDisposition |
1492 "execute a simple command (such as hostname) and |
1492 "execute a simple command (such as hostname) and |
1493 return the commands output as a collection of strings, |
1493 return the commands output as a collection of strings, |
1494 but only up to the given number of lines (if non-nil). |
1494 but only up to the given number of lines (if non-nil). |
1495 If the command generates more output, only the first nLines are returned |
1495 If the command generates more output, only the first nLines are returned |
1496 (but the command is allowed to finish execution). |
1496 (but the command is allowed to finish execution). |
1497 If the commands does not generate any output, an empty string is returned; |
1497 If the commands does not generate any output, an empty string is returned; |
1498 if the command fails, nil is returned." |
1498 if the command fails, nil is returned. |
|
1499 errorDisposition controls where the stdErr output should go, |
|
1500 and may be one of #discard, #inline or #stderr (default). |
|
1501 #discard causes stderr to be discarded (/dev/null), |
|
1502 #inline causes it to be written to smalltalks own stdout and |
|
1503 #stderr causes it to be written to smalltalks own stderr. |
|
1504 Nil is treated like #stderr" |
1499 |
1505 |
1500 |result| |
1506 |result| |
1501 |
1507 |
1502 PipeFailed ~~ true ifTrue:[ |
1508 PipeFailed ~~ true ifTrue:[ |
1503 PipeStream openErrorSignal handle:[:ex | |
1509 PipeStream openErrorSignal handle:[:ex | |
1540 |
1546 |
1541 "Modified: / 19.5.1999 / 14:25:02 / cg" |
1547 "Modified: / 19.5.1999 / 14:25:02 / cg" |
1542 ! |
1548 ! |
1543 |
1549 |
1544 getFullCommandOutputFrom:aCommand |
1550 getFullCommandOutputFrom:aCommand |
1545 "execute a simple command (such as hostname) and |
1551 "execute a command and |
1546 return the commands output as a collection of strings. |
1552 return the commands output as a collection of strings (including stdErr). |
1547 If the commands does not generate any output, an empty string is returned; |
1553 If the commands does not generate any output, an empty string is returned; |
1548 if the command fails, nil is returned." |
1554 if the command fails, nil is returned." |
1549 |
1555 |
1550 ^ self getCommandOutputFrom:aCommand maxNumberOfLines:nil |
1556 ^ self getCommandOutputFrom:aCommand maxNumberOfLines:nil errorDisposition:#inline |
1551 |
1557 |
1552 " |
1558 " |
1553 OperatingSystem getFullCommandOutputFrom:'mt status' |
1559 OperatingSystem getFullCommandOutputFrom:'mt status' |
1554 " |
1560 " |
1555 |
1561 |