8

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?

Abdallah_98
  • 1,331
  • 7
  • 17
  • 5
    `cat` *isn't* a windows/DOS program. In other words, if you type `cat` into the CMD prompt directly, you'll get the same result. In that sense, your python script is working as desired. – Paul H Jan 15 '21 at 01:07
  • 2
    If running a command [on Windows](https://stackoverflow.com/q/5469301) or running a command [on Linux](https://stackoverflow.com/q/3777301) you have to use different approaches. Your example would run on Linux but has to be changed to run on Windows. – bad_coder Jan 15 '21 at 09:02

1 Answers1

2

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

mTvare
  • 327
  • 1
  • 2
  • 14