不能从 powershell7 外部 运行 这个命令,默认的 powershell 工作
can't run this command from outside of powershell7, default powershell works
{哦,如果可能的话我不想使用 powershell}
我有一台 powershell 默认设置被破坏的电脑,所以我不得不使用 ps7,
如果我 运行 这个
import subprocess
import os
powershell = ''
if os.path.isfile('C:/Program Files/PowerShell/7/pwsh.exe'):
powershell = 'pwsh'
elif os.path.isfile('C:/Program Files (x86)/PowerShell/7/pwsh.exe'):
powershell = 'pwsh'
else:
powershell = 'powershell'
filename = 'test.exe'
subprocess.call(powershell + ' curl -H '+'\'Authorization: token ghp_xxxxxxxxxxxxxxxxxxx\''+' -H '+'\'Accept: application/vnd.github.v4.raw\''+' -o ' + filename + ' https://raw.githubusercontent.com/xxxxxx/[repo]/[branch]/'+filename+'\'', shell=True)
它说
The argument 'curl' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
但是如果我运行这个
curl.exe -H 'Authorization: token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxx' -H 'Accept: application/vnd.github.v4.raw' -o test.exe https://raw.githubusercontent.com/[user]/[repo]/[branch]/test.exe
直接在ps7中输入命令,有效,
我也试过运行在命令提示符下
"C:\Program Files\PowerShell\pwsh.exe" curl.exe -H 'Authorization: token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxx' -H 'Accept: application/vnd.github.v4.raw' -o test.exe https://raw.githubusercontent.com/[user]/[repo]/[branch]/test.exe
得到同样的错误
在命令提示符下尝试
cd [script location]
如果您的 PC 上有 python 作为一种语言,那么您应该能够做到:
python [script name].py
它应该 运行,如果不是,请尝试重新安装 power-shell 和 python。
这是使用 python 中的请求模块的方法。
import requests
headers = {
"Authorization": "token ghp_xxxxxxxxxxxx",
"Accept": "application/vnd.github.v4.raw",
}
#### for file less than 1 mb
response = requests.get(
"https://api.github.com/repos/[INSERT_OWNER_HERE]/[INSERT_REPO_HERE]/contents/[PATH/TO/FILE]", headers=headers
)
### If file is more than 1MB
response = requests.get(
"https://raw.githubusercontent.com/[INSERT_OWNER_HERE]/[INSERT_REPO_HERE]/[BRANCH]/[PATH/TO/FILE]", headers=headers
)
with open("test.exe", "wb") as f:
f.write(response.content)
这就是使用 powershell 和子进程的方法
import os
import subprocess
powershell = ""
if os.path.isfile("C:/Program Files/PowerShell/7/pwsh.exe"):
powershell = "pwsh"
elif os.path.isfile("C:/Program Files (x86)/PowerShell/7/pwsh.exe"):
powershell = "pwsh"
else:
powershell = "powershell"
filename = "test.exe"
subprocess.call(
powershell
+ " -Command curl.exe -H "
+ "'Authorization: token []'"
+ " -H "
+ "'Accept: application/vnd.github.v4.raw'"
+ " -o "
+ filename
+ " https://raw.githubusercontent.com/[INSERT_OWNER_HERE]/[INSERT_REPO_HERE]/[BRANCH]/"
+ filename,
shell=True,
)
如果需要,使用 PowerShell 并不难
$headers = @{Authorization = "token ghp_xxxxxxxxxxxx";Accept = "application/vnd.github.v4.raw"}
$URL = "https://github.com/WoLvES-2x0/tags/blob/main/test.exe"
Invoke-RestMethod -Uri $URL -Headers $headers
{哦,如果可能的话我不想使用 powershell} 我有一台 powershell 默认设置被破坏的电脑,所以我不得不使用 ps7, 如果我 运行 这个
import subprocess
import os
powershell = ''
if os.path.isfile('C:/Program Files/PowerShell/7/pwsh.exe'):
powershell = 'pwsh'
elif os.path.isfile('C:/Program Files (x86)/PowerShell/7/pwsh.exe'):
powershell = 'pwsh'
else:
powershell = 'powershell'
filename = 'test.exe'
subprocess.call(powershell + ' curl -H '+'\'Authorization: token ghp_xxxxxxxxxxxxxxxxxxx\''+' -H '+'\'Accept: application/vnd.github.v4.raw\''+' -o ' + filename + ' https://raw.githubusercontent.com/xxxxxx/[repo]/[branch]/'+filename+'\'', shell=True)
它说
The argument 'curl' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
但是如果我运行这个
curl.exe -H 'Authorization: token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxx' -H 'Accept: application/vnd.github.v4.raw' -o test.exe https://raw.githubusercontent.com/[user]/[repo]/[branch]/test.exe
直接在ps7中输入命令,有效,
我也试过运行在命令提示符下
"C:\Program Files\PowerShell\pwsh.exe" curl.exe -H 'Authorization: token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxx' -H 'Accept: application/vnd.github.v4.raw' -o test.exe https://raw.githubusercontent.com/[user]/[repo]/[branch]/test.exe
得到同样的错误
在命令提示符下尝试
cd [script location]
如果您的 PC 上有 python 作为一种语言,那么您应该能够做到:
python [script name].py
它应该 运行,如果不是,请尝试重新安装 power-shell 和 python。
这是使用 python 中的请求模块的方法。
import requests
headers = {
"Authorization": "token ghp_xxxxxxxxxxxx",
"Accept": "application/vnd.github.v4.raw",
}
#### for file less than 1 mb
response = requests.get(
"https://api.github.com/repos/[INSERT_OWNER_HERE]/[INSERT_REPO_HERE]/contents/[PATH/TO/FILE]", headers=headers
)
### If file is more than 1MB
response = requests.get(
"https://raw.githubusercontent.com/[INSERT_OWNER_HERE]/[INSERT_REPO_HERE]/[BRANCH]/[PATH/TO/FILE]", headers=headers
)
with open("test.exe", "wb") as f:
f.write(response.content)
这就是使用 powershell 和子进程的方法
import os
import subprocess
powershell = ""
if os.path.isfile("C:/Program Files/PowerShell/7/pwsh.exe"):
powershell = "pwsh"
elif os.path.isfile("C:/Program Files (x86)/PowerShell/7/pwsh.exe"):
powershell = "pwsh"
else:
powershell = "powershell"
filename = "test.exe"
subprocess.call(
powershell
+ " -Command curl.exe -H "
+ "'Authorization: token []'"
+ " -H "
+ "'Accept: application/vnd.github.v4.raw'"
+ " -o "
+ filename
+ " https://raw.githubusercontent.com/[INSERT_OWNER_HERE]/[INSERT_REPO_HERE]/[BRANCH]/"
+ filename,
shell=True,
)
如果需要,使用 PowerShell 并不难
$headers = @{Authorization = "token ghp_xxxxxxxxxxxx";Accept = "application/vnd.github.v4.raw"}
$URL = "https://github.com/WoLvES-2x0/tags/blob/main/test.exe"
Invoke-RestMethod -Uri $URL -Headers $headers