How to execute program or batch file? [duplicate] - python

This question already has answers here:
Run a .bat file using python code
(9 answers)
Closed 2 years ago.
I have installed PyCharm to using Python language on Windows 10.
I'm trying to execute command from Linux command in PyCharm, I used this code:
import subprocess
subprocess.run("cat",shell=True,text=True)
But I get this error:
'cat' is not recognized as an internal or external command, operable program or batch file.
I want to execute several commands another such as this example, but all commands raise the same error. How to solve this?

Cat is a binary included in Unix systems, since windows isn't based on Unix, it wouldn't work. You should rather try the TYPE command in Windows

Related

I cant hide python exe file console [duplicate]

This question already has answers here:
How do I hide the console when I use os.system() or subprocess.call()?
(5 answers)
Closed 3 years ago.
I wrote a script , this script modify some files on system.
I used this lib with no console option but when i run script some terminals show up for 1 second and then they will hide.
I used Os.system() in my code.
What should i do to run the script completely silent?
If you name your files with the ".pyw" extension, then windows will execute them with the pythonw.exe interpreter. This will not open the cmd console for running your script.

How do I input data into a command prompt from within python 2.7 [duplicate]

This question already has answers here:
Running windows shell commands with python
(7 answers)
Closed 4 years ago.
I want to open a cmd and then input data into the command line from python. I plan to call PEST calibration software to open from within python and I want to start by opening a cmd.
I am using Python 2.7 and so subprocess doesn't seem to work. I have tried os.system('cmd') and I can open the prompt but I can't input any data.
import os
os.system('cmd')
You should be able to pass the exact resulting string to os.system(). Ex:
os.system('notepad.exe')
In other words, os.system behaves the same way a console would.

'more' is not recognized as an internal or external command, operable program or batch file [duplicate]

This question already has answers here:
Using interpreter to lookup module 'sys' in Python
(4 answers)
Closed 4 years ago.
I'm in the python help then modules.
Then any module I type I get the
'more' is not recognized as an internal or external command, operable program or batch file.
Is there an easy answer? Thanks
Python 3.4 on windows 7 64 bit.
Try this command in cmd:
python -m pydoc modulename ***-type the module name here
Note: This will only work if you run cmd as admin otherwise you will get the same error (the 'more' error)

Execute terminal commands in python3 [duplicate]

This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 7 years ago.
I am on a Raspberry Pi, and I am using a program called fswebcam, which allows you to take pictures with a webcam.
~$ fswebcam image.jpg
That command if entered in terminal takes a picture and saves it to your computer, however I want to build a simple python program that can access the terminal and execute that same command as I have listed above.
I have tried to import os and use os.system('fswebcam image.jpg') But it isn't working for me.
How can I have python execute terminal commands?
Use the subprocess module:
import subprocess
subprocess.Popen(["fswebcam", "image.jpg"])

Using arguments in python [duplicate]

This question already has answers here:
How to read/process command line arguments?
(22 answers)
Closed 8 years ago.
I wrote a code using Python in Geany within windows and I'm using arguments in the code. I execute the program within the Geany so I don't know how to use arguments.
How could I convert the program to be be run as a standalone system, not to be run from within an IDE.
how could I use terminal in windows to run the code like this :
John~/home/args -> ./test.py -h
In Notepad, write what you would in terminal...
python test.py -h
Save it as a .bat file... Then you can run the bat file :)
PS. This goes for anything you wish to run in CMD

Categories

Resources