输出未重定向到窗口任务中的文件



我还应该声明我在Windows容器中运行它。

我正在尝试在文件中获取 aws.cmd 的输出,但是在任务中运行时它不会发送任何输出 - 我不知道为什么。

如果我创建以下脚本:

'get-date | out-file c:logsdate.txt; C:userscontaineradministratorappdataRoamingPythonPython37Scriptsaws.cmd --version | out-file -append c:logsdate.txt; getdate | out-file -append c:logsdate.txt' > getdate.ps1

然后创建一个任务:

schtasks --% /create /tn "test-date" /sc minute /mo 1 /ru SYSTEM /tr "powershell -file c:/getdate.ps1"

该任务运行脚本并将其写入文件:

PS C:> cat C:logsdate.txt
Wednesday, May 23, 2018 2:38:00 PM

Wednesday, May 23, 2018 2:38:02 PM

然而,当直接从控制台运行时,它会将输出写入文件:

PS C:> C:userscontaineradministratorappdataRoamingPythonPython37Scriptsaws.cmd --version > C:logsconsoletest.txt
PS C:> cat C:logsconsoletest.txt
aws-cli/1.15.24 Python/3.7.0b4 Windows/10 botocore/1.10.24

这是怎么回事?我将 aws 命令夹在两个都运行的获取日期命令之间,因此 aws 命令必须正确执行,因为它运行两个获取日期命令。

编辑:现在我真的很困惑,如果我用废话替换 aws 命令,它仍然运行两个获取日期命令,并在日志文件中看到它们的输出。例如,在脚本中将 aws 命令替换为"blah.exe--something"并执行任务,它仍然将两个获取日期输出写入文件而不会出错。为什么?!脚本至少应该在那个错误的命令下失败!我不明白发生了什么。

编辑2(重定向所有输出(:

try {
C:UsersContainerAdministratorAppDataRoamingPythonPython37Scriptsaws.cmd --version *>> c:logsdate.txt
}
catch {
$_.Exception | out-file c:logsdate.txt
}
get-date | out-file -apend c:logsdate.txt

重定向所有输出,我看到此错误:

C:UsersContainerAdministratorAppDataRoamingPythonPython37Scriptsaws.cmd
: Traceback (most recent call last):
At C:getdate.ps1:1 char:6
+ try {C:UsersContainerAdministratorAppDataRoamingPythonPython37 ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (Traceback (most recent call last)
::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
File "C:UsersContainerAdministratorAppDataRoamingPythonPython37Scripts
aws.cmd", line 50, in <module>
import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'
pip install awscli --upgrade --user

我安装了 --user 开关,将其删除到程序文件中,并且可以作为系统用户从任务中访问它

最新更新