-3

I need to return the answer of CMD command to a variable in Python, I've try using a some OS modules but nothing them work propely.

E.G TASKLIST, I need return all data in CMD to a variable in Python, can be any command, just need the value

arp_inf = command(arp -a 192.168.100.1) 

print(arp_inf) # Ip Adress 192.168.100.1 Phisic Adress.....
GuiNobre
  • 5
  • 2

1 Answers1

0

I'm assuming you want to capture the output of a command. Here is an example with tasklist:

import subprocess
p = subprocess.run('tasklist', capture_output=True)

# p has the output in stdout and the error in stderr:
for line in p.stdout.splitlines():
    print(line)
nonDucor
  • 2,057
  • 12
  • 17