[英]How to run ps1 from power shell which contain ()in directory path
我正在嘗試使用 python 運行 ps1 文件
import os
os.system('powershell -Command' + ' ' +'powershell -ExecutionPolicy RemoteSigned C:\hoge\test.ps1')
但是dir路徑就像在它下面不會運行。
'powershell -Command' + ' ' +'powershell -ExecutionPolicy RemoteSigned C:\hoge(foo)\test.ps1'
看起來 poweshell 只識別 C:\hoge
有什么方法可以在某些情況下運行 ps1 嗎? 非常感謝。
您只需要一個powershell.exe
調用,並且由於您正在調用腳本文件( *.ps1
),因此請使用-File
CLI參數。
在'...'
Python 字符串文字中,逐字\
字符必須轉義為\\
如果您的*.ps1
腳本的文件路徑包含空格或其他 PowerShell 元字符,例如(
和)
,則必須在命令行中將其括在"..."
中。
import os
os.system('powershell.exe -ExecutionPolicy RemoteSigned -File "C:\\hoge(foo)\\test.ps1"')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.