How can I call a batch file within another batch file?

2

1

trying to call a batch file within another batch file the script completes the synchronization of the remote folders but then fails to call the other batch file.

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Test\TestLog.log" /ini=nul ^
/command ^
"open sftp://test/ -hostkey=""ssh-dss 2048 xxxxxxxxxxxxxxxxxxxxxxxxx=""" ^
"synchronize remote \\Please\Send\Some\Help /Dir/Test" ^
"exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)

exit /b %WINSCP_RESULT%

CALL movefile

pause

Westfall_T

Posted 2018-06-18T16:31:58.103

Reputation: 65

Answers

0

Simply move the call command to be above the exit command or else it will exit before calling.


What to Change

This. . .

exit /b %WINSCP_RESULT%
CALL movefile
pause

Becomes this. . .

CALL movefile
pause
exit /b %WINSCP_RESULT%

Script

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Test\TestLog.log" /ini=nul ^
/command ^
"open sftp://test/ -hostkey=""ssh-dss 2048 xxxxxxxxxxxxxxxxxxxxxxxxx=""" ^
"synchronize remote \\Please\Send\Some\Help /Dir/Test" ^
"exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)

CALL movefile
pause
exit /b %WINSCP_RESULT%

Note: You will also want to ensure the batch script file being called actually exists so confirm that is the accurate location from the executing batch script command that calls movefile.

Pimp Juice IT

Posted 2018-06-18T16:31:58.103

Reputation: 29 425