Pls. help me recreate shell trick

Fernando Pérez fperez528 at yahoo.com
Thu Nov 22 12:06:04 EST 2001


Daniel Dittmar wrote:

>> This was achieved as follows:
>>
>> $ECHO rm -r /
>>
>> where ECHO was either set to "echo" or nothing according to a command
> 

Another option:

import os

def xsys(cmd,verbose=0,debug=0,head=''):
    """Execute a system command, but optionally print it.
    With debug=1, only prints."""

    stat = 0
    if verbose or debug: print head+cmd
    if not debug: stat = os.system(cmd)
    return stat


cheers,

f



More information about the Python-list mailing list