Python3 is not printing the output in the desired order when using subprocess.call
Your subprocess prints the output by itself, and the function returns the return code. The print order could be influenced by Python's output buffering settings.
Just use subprocess.check_output
to get the output that the command would print.
import subprocess, shutil
print ("Current running kernel version on the system is:\n", subprocess.check_output([shutil.which("uname"), "-a"]))
edit
As I imagined, the Python 2 version is
print "Current running kernel version on the system is:\n", subprocess.call(["uname", "-r"])
The Python 2 print statement evaluates and prints each expression in sequence.
The Python 3 print function is just a regular function, so arguments are evaluated first, and the function prints the evaluated values
Since the side effect of invoking uname is to print the uname, it gets printed first, followed by print doing its thing - printing the text and the return value of call
, the zero return code.