-1

I am new in this Language. So I want to Write a Python App. Which will get input From User and Paste it in the CMD step by step. Cause I have Multiple Input.

What I need to Know:

  1. Suppose I give something command like "date" and cmd is asking me the new date. so I need to take the value before execute the command for user.
  2. Similar i Want to take 2-3 input from the user before execute the command than the command will be Execute and the asking things from cmd will be filled up by Python automatically.
  3. I also want to do it in background .Dont want that user is watching the programme is using cmd.
  4. Want to Show log in GUI. Like First input is pasting... second input is pasting... pasted!

Advance Thanks to All Mates

Shakil Ahmed
  • 24
  • 10

1 Answers1

0
import os
command = input("Enter the command to be executed on CMD : ")
os.system(f'cmd /c "{command}"') #Executes the command on CMD which is running in  background and it gets closes as soon as the output is generated

The above code won't open up the CMD and type the command but rather execute CMD in background and would print the output of command.

For example :

>>> Enter the command to be executed on CMD : net user
>>> User accounts for \\DESKTOP-XYZ

-------------------------------------------------------------------------------
Administrator            DefaultAccount           Guest
USER1                    USER2                    GuestAcc
The command completed successfully.

And if you'd like to store the output of the command in a text file then replace
os.system(f'cmd /c "{command}"') with os.system(f'cmd /c "{command}>txt_file_name.txt"')

So the final code if you'd also like to store the output would be:

import os
command = input("Enter the command to be executed on CMD : ")
os.system(f'cmd /c "{command}>txt_file_name.txt"') 
'''
It executes the command and stores the output in .txt file named as 'txt_file_name.txt' 
which is saved in the same path as of the source code
'''

There are also some commands which need admin permissions to be executed. For those commands above code would return an error and would not execute properly. If you wish to execute the admin commands then you may refer to this

CopyrightC
  • 857
  • 2
  • 7
  • 15