Differences

This shows you the differences between the selected revisions of the page.

guide_debugging_scheduler 2020-12-23 guide_debugging_scheduler 2023-01-20 (current)
Line 11: Line 11:
</code> </code>
-If the task works correctly from Command prompt, see [[faq_scheduler|My script works fine when executed manually, but fails or hangs when run by Windows Scheduler, SSIS or other automation service. What am I doing wrong?]]+Execute the command from an independent working directory (neither WinSCP installation folder ''C:\Program Files (x86)\WinSCP'', &winpath nor script folder, nor transfer source nor destination folder). Common cause of problems is that your command or script rely on a specific working directory, and your scheduled tasks runs from elsewhere. 
 + 
 +If the command works correctly from Command prompt, see [[faq_scheduler|*]]
If the task fails even when run from Command prompt, inspect a console output of the task for any error. If you see an error, check list of [[messages|common error messages]] or search this website for the error. To check for an error in console output, it is [[troubleshooting#scripting|recommended]] to use ''[[executables|winscp.com]]''. If the task fails even when run from Command prompt, inspect a console output of the task for any error. If you see an error, check list of [[messages|common error messages]] or search this website for the error. To check for an error in console output, it is [[troubleshooting#scripting|recommended]] to use ''[[executables|winscp.com]]''.
Line 17: Line 19:
If the problem is not obvious from the output, enable logging to a file as described below. If the problem is not obvious from the output, enable logging to a file as described below.
-===== Inspecting Session Log =====+===== [[session_log]] Inspecting Session Log =====
Next step is to enable logging to file (you should have logging enabled anyway) and inspect the log. Use ''[[commandline#logging|/log]]'' command-line parameter. Next step is to enable logging to file (you should have logging enabled anyway) and inspect the log. Use ''[[commandline#logging|/log]]'' command-line parameter.
Line 32: Line 34:
</code> </code>
-If you know that the task failed with [[scripting#result|exit code 1]], see [[faq_exit_code|Why is WinSCP returning non zero exit code?]] to learn what to look for in the log.+If you know that the task failed with [[scripting#result|exit code 1]], see [[faq_exit_code|*]] to learn what to look for in the log.
===== [[output]] Inspecting Output Log ===== ===== [[output]] Inspecting Output Log =====
Line 75: Line 77:
Particularly, when debugging problems starting the PowerShell script itself, it is useful to wrap the ''powershell.exe''/''pwsh.exe'' command to a batch file. That will allow you to redirect a PowerShell output to a file, the [[#output|same way as shown above for ''winscp.com'']]. Particularly, when debugging problems starting the PowerShell script itself, it is useful to wrap the ''powershell.exe''/''pwsh.exe'' command to a batch file. That will allow you to redirect a PowerShell output to a file, the [[#output|same way as shown above for ''winscp.com'']].
-If you know that your PowerShell is starting, but fails somewhere before WinSCP session log ([[library_session#sessionlogpath|''Session.SessionLogPath'']]) is created, and you do not want to create the batch file wrapper, use [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript|''Start-Transcript'' cmdlet]] in the PowerShell script itself. Using it, you can capture all the PowerShell output that you would otherwise see on the PowerShell console. Put the following line to the beginning of your script (but after the ''param'' statement, if you have one):+If you know that your PowerShell is starting, but fails somewhere before WinSCP session log ([[library_session#sessionlogpath|''Session.SessionLogPath'']]) is created, and you do not want to create the batch file wrapper, use [[https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript|''Start-Transcript'' cmdlet]] in the PowerShell script itself. Using it, you can capture all the PowerShell output that you would otherwise see on the PowerShell console. Put the following line to the beginning of your script (but after the ''param'' statement, if you have one):
<code powershell> <code powershell>
Line 83: Line 85:
===== Further Reading ===== ===== Further Reading =====
-  * [[faq_environment|Why does WinSCP not work in a new environment (operating system, machine, user account, network), when it works for me in a different environment already?]] +  * [[faq_environment|*]] 
-  * [[faq_script_result|How do I know that script completed successfully?]] +  * [[faq_script_result|*]] 
-  * [[faq_script_vs_gui|Why I cannot connect/transfer using script, when I can using GUI (or vice versa)?]]+  * [[faq_script_vs_gui|*]] 
 +  * [[troubleshooting#scripting|Troubleshooting scripting/automation issues]]

Last modified: by martin