【问题标题】:Task scheduler not producing output with powershell script任务调度程序不使用 powershell 脚本生成输出
【发布时间】:2021-01-22 20:46:14
【问题描述】:

我通过任务计划程序执行了一项基本任务,该任务调用了执行 Python 脚本的 Powershell 脚本。出于某种原因,当我通过任务计划程序调用 Powershell 脚本时,它不会产生任何输出,当我查看历史日志时,它也成功完成。我可以通过终端手动运行 Powershell 脚本,一切正常。其他人遇到过这个问题吗?谢谢!

这是我的“编辑操作”参数:

程序/脚本: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

添加参数(可选): -ExecutionPolicy Bypass C:\Users\MyUserName\Documents\MyFolderName\MyPowerShellScript.ps1

开始于(可选): C:\Users\MyUserName\Documents\MyFolderName\

任务也在Windows Vista, Windows Server 2008中配置,将Run whether user is logged on or not

这是我的 .ps1 脚本中的内容:

$Path = "C:\Users\MyUserName\Documents\MyFolderName"
cd $Path
pipenv run python "main.py"

*edit 我收到错误代码 0x1 作为Last Run Result,它应该是 0x0

【问题讨论】:

  • 请问,你的 Powershell 脚本在哪里?
  • @MarcSances C:\Users\MyUserName\Documents\MyFolderName\MyPowerShellScript.ps1
  • 我的意思是您应该粘贴该脚本的代码,以便我们可以查看它是否以某种方式相关......
  • @MarcSances Powershell 脚本在我手动运行时有效,但在我使用任务计划程序执行时却无法正常工作。
  • 请编辑您的问题以包含代码。我们需要minimal, reproducible example 来帮助您

标签: python powershell scheduled-tasks taskscheduler windows-task-scheduler


【解决方案1】:

更改参数选项有效:

添加参数(可选):

-ExecutionPolicy Bypass -file "C:\Users\MyUserName\Documents\MyFolderName\MyPowerShellScript.ps1"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多