Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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 使用os.system调用PowerShell时出错_Python_Powershell_Powershell 5.0 - Fatal编程技术网

Python 使用os.system调用PowerShell时出错

Python 使用os.system调用PowerShell时出错,python,powershell,powershell-5.0,Python,Powershell,Powershell 5.0,当我尝试从Python函数调用powershell时,收到以下错误: 无法加载PSReadline模块。控制台在没有PSReadline的情况下运行 我有一个名为ps\u cli()的函数,它是:os.system(“powershell-NoProfile”) 当我调用它时,我得到以下行为/错误: 这以前在Windows 7和8机器上工作过(我目前没有访问权限),从我读到的一些信息来看,可能与Windows 10机器上的PowerShell 5有关。我正在编写的工具背后的想法是,它可以在具有

当我尝试从Python函数调用
powershell
时,收到以下错误:

无法加载PSReadline模块。控制台在没有PSReadline的情况下运行

我有一个名为
ps\u cli()
的函数,它是:
os.system(“powershell-NoProfile”)

当我调用它时,我得到以下行为/错误:

这以前在Windows 7和8机器上工作过(我目前没有访问权限),从我读到的一些信息来看,可能与Windows 10机器上的PowerShell 5有关。我正在编写的工具背后的想法是,它可以在具有适当权限的帐户上与任何现代版本的Windows协同工作。由于我正在编写更高级的脚本,这似乎会导致几秒钟的延迟,因此我想了解如何在不执行以下操作的情况下消除此问题:

使用参数
-PSConsoleFile
和以前使用
导出控制台导出的PSConsoleFile打开Powershell


这是在我看到的一篇论坛帖子中提出的。任何想法都将不胜感激

PSReadline
-模块是Powershell 5.0(在Win10上)中的一个新内置模块,提供了增强的控制台体验。因为它是内置的,所以executionpolicy不应该有问题(即使出于某种原因它没有被签名),但是检查它也不会有什么坏处。这行吗

os.system("powershell -NoProfile -ExecutionPolicy ByPass")
您正在使用第三方控制台吗?除了
conhost.exe
(cmd和powershell使用的windows中的默认设置)之外,该模块可能与其他控制台不兼容

一个棘手的解决方法是简单地清除屏幕:

os.system("powershell -NoProfile -NoExit -Command cls")

这可能是因为Powershell中的策略不运行不受信任的脚本吗?@GLaDOS不,我不这么认为,因为它最终启动了控制台。此外,它没有试图执行的“脚本”,因此我怀疑ExecutionPolicy是否会发挥作用。当然值得一查。你搞定了@GLaDOSwe我们必须做的,因为我们可以。是的,我尝试了执行策略,结果意外地解决了它,所以很酷。我使用的是第三方控制台-Cmder(基于Conemu的控制台)-但看起来很好用