Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Windows和MacOS中运行shell脚本_Python_Python 3.x_Operating System_Sh - Fatal编程技术网

Python 在Windows和MacOS中运行shell脚本

Python 在Windows和MacOS中运行shell脚本,python,python-3.x,operating-system,sh,Python,Python 3.x,Operating System,Sh,我正在尝试制作一个与Windows和Mac OS兼容的python3脚本。我已经让脚本在Mac上运行,现在我正试图让它在Windows上运行。看起来我在使用系统特定的命令('clear'和'sh'),这导致了一些问题 以下是脚本: import os clear = lambda: os.system("clear") while True: os.system("echo \U0001F525=-=-=-=-=-=-Main Menu=-=-=-=-

我正在尝试制作一个与Windows和Mac OS兼容的python3脚本。我已经让脚本在Mac上运行,现在我正试图让它在Windows上运行。看起来我在使用系统特定的命令('clear'和'sh'),这导致了一些问题

以下是脚本:

import os

clear = lambda: os.system("clear")


while True:
    os.system("echo \U0001F525=-=-=-=-=-=-Main Menu=-=-=-=-=-=-\U0001F525")
    os.system("echo")
    choice = str(
        input(" 0. Press '0' to perform environment setup.\n 1. Press '1' to delete files.\n 2. Press '2' to exit.\n\n> ")
    )
    clear()
    if choice == "0":
        os.system("sh config.sh")
    elif choice == "1":
        os.system("echo Entering delete files mode")
    elif choice == "2":
        exit()

以下是我在windows上运行此文件时遇到的错误:

'clear' is not recognized as an internal or external command,
operable program or batch file.
'sh' is not recognized as an internal or external command,
operable program or batch file.

ECHO is on.
下面是我试图在
config.sh

python3 -m venv env
source env/bin/activate
pip3 install -r requirements.txt
最后,这是我的requirements.txt文件

flask

编辑问题以显示您已经尝试过的内容。
clear
在windows上是
cls
(哑巴,我知道)。对于windows shell脚本,使用扩展名为
.bat
的文件并调用
os.system('C:\Path\to\batfile.bat')
您可以根据主机操作系统将标志设置为True/False,然后使用相应的命令和
sh
vs
bat
文件。查看Python
平台
模块。为什么要使用
os.system
运行
echo
?Python有一个
print
函数。