- Thread Author
-
- #1
Hi,
I'm new of this thread and I do not know if this is the right section of the forum. I'm under windows 10 1803 64 bit.
I have two scripts (.cmd and .ps1) which execute the same operation. The scripts work well if I run them from cmd or powershell while they do not work if I use schtasks.
In particular, the job is created correctly and it starts after login, but the scripts fail to execute. The script executes a program in a new windows, but it is closed immediately and it is not possible to catch the error.
I tried to redirect the output of cmd in order to capture the error, but it does not work.
Do you have any suggestion?
I'm new of this thread and I do not know if this is the right section of the forum. I'm under windows 10 1803 64 bit.
I have two scripts (.cmd and .ps1) which execute the same operation. The scripts work well if I run them from cmd or powershell while they do not work if I use schtasks.
In particular, the job is created correctly and it starts after login, but the scripts fail to execute. The script executes a program in a new windows, but it is closed immediately and it is not possible to catch the error.
I tried to redirect the output of cmd in order to capture the error, but it does not work.
Code:
start cmd /c program arg1 arg2 2^> out_err.txt
Last edited:
- Thread Author
-
- #3
Thank you very much. Your workaround worked, by using cmd /k I found that the problem was related to the working directory.
Both the following works well.
I would like to get the same result via powershell:
However, in this case adding the path does not change the effect.
Both the following works well.
Code:
start /D %scriptPath% %scritpPath%program arg1 arg2
Code:
start /D %scriptPath% cmd /c %scriptPath%program arg1 arg2
I would like to get the same result via powershell:
Code:
Start-Process -WorkingDirectory $path -FilePath "$path\program" -ArgumentList "arg1 arg2" -WindowStyle Maximized
However, in this case adding the path does not change the effect.
- Thread Author
-
- #5
I solved in this way:
Schtsk:
Code:
Start-Process -WorkingDirectory $path -FilePath "$path\program" -ArgumentList "arg1 arg2" -WindowStyle Maximize
Schtsk:
Code:
PowerShell -ExecutionPolicy Bypass -NoProfile -InputFormat None -File C:\path\script.ps1
Similar threads
- Solved
- Replies
- 2
- Views
- 2K