Proxy.bat文件包含:
@ECHO OFF 1>NUL 2>NUL
powershell -Command $pword = read-host "enter password" -AsSecureString ; $BSTR=
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ;
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=
<.tmp.txt & del .tmp.txt
>NUL set http_proxy=http://%1:%password%@abc.yz.com:80
>NUL set https_proxy=https://%1:%password%@abc.yz.com:80
>NUL set no_proxy=abc.yz.com
Python 代码
from subprocess import Popen
import subprocess
def run_batch_file(file_path):
Popen(file_path,creationflags=subprocess.CREATE_NEW_CONSOLE)
run_batch_file("D:\\gower\\proxy.bat")
密码请求未执行。请问如何使脚本能够响应密码,请提供建议。
<.tmp.txt & del .tmp.txt
前面有一个多余的换行符... - aschipfl