-2

I am attempting to print to the terminal in Python using the following code obtained from similar questions:

cmd = 'test'
output = subprocess.Popen(cmd, stdout=subprocess.PIPE ).communicate()[0]
print(output)

However doing this gives me the output of:

b''

How can I fix my code to properly output to the terminal?

martineau
  • 119,623
  • 25
  • 170
  • 301
arcade16
  • 1,535
  • 4
  • 23
  • 45

1 Answers1

6

From the man pages:

test - check file types and compare values

A program to test files. And when you run it on the command line .. it simply prints nothing (because this command works on the file names provided to it; and as you are not passing any arguments, it simply has nothing to say)

And that output there tells you that (where b'' means: empty array of byte octets; see here for details on that).

So the real answer here: before you start wondering what a tool does when you call it within python ... run it directly on the shell.

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • The link I am providing there ... explains exactly that b'' part. – GhostCat Jan 29 '17 at 19:21
  • 3
    So you have no clue what you are doing and expect other people to explain it to you? Your **own** code is using sub process to start a *sub process* to run the command that **you** are passing to it. That command is named test. And Assuming that you are using a Linux system, I explained to you what "test" is about. – GhostCat Jan 29 '17 at 19:23