Oct-13-2016, 03:55 PM
I wrote a function which accepts an argument (a Linux command) and then runs subprocess.check_output
however, this is what I got for command output:
[jdavis@localhost ~]$ ./ex1
the output value is:
b'/home/jdavis\n'
[jdavis@localhost ~]$
Why do I get the 'b' prepended and the '\n at the end? and how to I prevent this?
#!/usr/local/bin/python3.5 # # # FUNCTIONS # def run_command(command): p = subprocess.check_output(command, stdin=None, stderr=None, timeout=None, shell=True, universal_newlines=False ) print('the output value is: ') print(p) # # # END OF FUNCTIONS # import subprocess run_command('pwd')when invoking this function with the argument 'pwd' I expected to get a string containing '/home/jdavis'
however, this is what I got for command output:
[jdavis@localhost ~]$ ./ex1
the output value is:
b'/home/jdavis\n'
[jdavis@localhost ~]$
Why do I get the 'b' prepended and the '\n at the end? and how to I prevent this?