0

I'm very new to python.

I wanted to make a Python File (script) that would run cmd and then run a Command for example: net user. I tried this

import os os.system ('start cmd') 

but I still need help.

7
  • 2
    Be sure to check your question before posting. Commented Apr 19, 2019 at 12:31
  • have a look at this stackoverflow.com/questions/89228/… Commented Apr 19, 2019 at 12:31
  • What did you see when you tried it? Commented Apr 19, 2019 at 12:32
  • 1
    Possible duplicate of Calling an external command in Python Commented Apr 19, 2019 at 12:32
  • 1
    Just to be clear, you want to open a command prompt and make that command prompt run a command or do you want to just run a program? Commented Apr 19, 2019 at 12:33

1 Answer 1

1

You can use subprocess:

import subprocess import sys command = "net user" subprocess.call(command,shell=True,stdout=sys.stdout) 

Example output:

User accounts for \\COMPUTER ------------------------------------------------------------------------------- user1 user2 user3 The command completed successfully. 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.