0

I want to write information about this tracing in file:

site = input('Input URL:')
trac = os.system('tracert '+site)

but trac equals 0 and I don't know how to get access to os.system() information.

1 Answers1

1

Here :

trac = os.system('tracert '+site)

the return value is :

Linux

On Unix, the return value is the exit status of the process encoded in the format specified for wait().

or

Windows

On Windows, the return value is that returned by the system shell after running command, given by the Windows environment variable COMSPEC.

For more information about that see python's documentation about os.system.

But if you want to retrieve outputs of your system call then use subprocess.check_output method of subprocess module instead and try to change your code like that :

import subprocess
site = input('Input URL:')
trac = subprocess.check_output(["tracert", site])
# Do something else

Formerly you can did it with os.popen but since Python 2.6 it's deprecated :

Deprecated since version 2.6: All of the popen*() functions are obsolete. Use the subprocess module.

Jankov_n
  • 103
  • 1
  • 11
  • @TobySpeight fixed. – Jankov_n May 24 '17 at 10:47
  • I don't have enough reputation to post the stackoverflow's thread on my answer so I put here : [Python, os.system for command-line call (linux) not returning what it should?](https://stackoverflow.com/questions/3791465/python-os-system-for-command-line-call-linux-not-returning-what-it-should) – Jankov_n May 24 '17 at 10:48