Skip to main content

Posts

Showing posts with the label command

Python Pipe

Pipes can be used in python using the popen command. os.popen(command[, mode[, bufferSize]]). The default mode is read which can also be explicitly indicated by "r" as shown in the example below. The parameter bufferSize can be 0 (no buffering), 1 (line buffering), negative(system default buffering) and positive values greater than 1 (number defines the buffer size to be used). #Open a pipe to or from command import os # shell command to show all the files in current directory with ".py" in the file name shellCommand = ' ls | grep .py' pipe = os.popen(shellCommand,"r") while True: # read each output line line = pipe.readline() if not line: break print 'outputLine: ' print line

shutdown

We may think that why to bother typing commands when using the GUI to shutting down the computer is easy and straight. But at time we may want to shut down the computer after some time when the download finishes or some other task completes. But we cannot wait until that time. So we can use shutdown command in such cases. For example, if you want to shut down the computer at 2:12 pm then you can use the following command in your ubuntu box: sudo shutdown -h 14:12 "Going to Shutdown at 2:12 pm"