-
Notifications
You must be signed in to change notification settings - Fork 62
Simple mode
In simple mode you execute commands in a blocking way. That means that execution of
`ping -n 4 8.8.8.8
will not return until it is finished. When it's done a Result of the execution becomes available to you. You can assign the Result to your variable like this:
result = `ping -n 4 8.8.8.8
Result is a class that provides several properties to you:
stdout
property returns the whole text of the command stdout to you.
stderr
the same but for stderr.
stdout_lines
is a list of all stdout lines. It may be convenient if you want to iterate over all lines or access some specific line by index. Lines in this list do not contain the line separator at the end.
stderr_lines
the same but for stderr.
returncode
return code of the command executed
###Syntactic sugar
It is possible to iterate over lines of result
result = `ls -l somedir
for line in result:
print line.upper()
Compaire two results (by text)
`echo 1` == `echo 1` # True
`echo 1` == `echo 2` # False
Extract stdout from result
result = `ls -l somedir
print result
The latest is equivalent to print str(result)
or print result.stdout