Windows task fails but throws no errors and writes no output

This creates a task that works and writes to a file:

schtasks --% /create /tn "test" /sc minute /mo 10 /ru SYSTEM /tr "powershell get-date | out-file -Encoding:ascii c:\log.log"

This does not create a log file and i cant see any errors:

schtasks --% /create /tn "test2" /sc minute /mo 10 /ru SYSTEM /tr "powershell someexe --help | out-file -Encoding:ascii c:\otherlog.log"

The second command isn't writing to the log file, why? Even if it fails it should still be writing to the file. If I run this from the command line it still writes to the file:

PS C:\> powershell doesntexist --help | out-file -Encoding:ascii c:\fail.log
PS C:\> cat .\fail.log
doesntexist : The term 'doesntexist' is not recognized as the name of a cmdlet, function, scrip
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ doesntexist --help
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (doesntexist:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

So I cant understand why the first task is writing to a file and the second one is not

1
задан 22 May 2018 в 10:04
1 ответ

powershell someexe --help или даже powershell someexe.exe --help : если имя исполняемого файла используется без префикса пути, то он запускается только в том случае, если он находится в пути среды. PowerShell не запускается из текущего каталога без него.

Используйте абсолютный путь к исполняемому файлу в аргументе / tr (например, powershell c: \ myexes \ someexe.exe --help ) .

Избегайте использования относительных путей (например, powershell. \ Someexe.exe --help ), потому что текущий каталог . \ немного неясен как start- в каталоге не определено точно и однозначно.

3
ответ дан 3 December 2019 в 18:27

Теги

Похожие вопросы