Page 1 of 1
Call .bat from another machine
Posted: 23 Jan 2015 07:47
by mwatsondhs
When I run the code below it goes to the rename function but it never changes the directory.
P: is on a different machine and I think that this is the problem. Is this a permissions
problem or a coding problem? Any thoughts?
Thanks,
Mark
Code: Select all
@echo off
setlocal enabledelayedexpansion
FOR /F "delims=" %%G in ('dir sls316*.pdf /a-d /b /od') do set "newest=%%~G"
copy "%newest%" p:\"BCS Reports"\Temp
call :rename
:rename
echo in rename function
cd p:\"BCS Reports"\Temp
call rename.bat
Re: Call .bat from another machine
Posted: 23 Jan 2015 07:57
by Squashman
H:\>cd /?
Displays the name of or changes the current directory.
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
.. Specifies that you want to change to the parent directory.
Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.
Use the /D switch to change current drive in addition to changing current
directory for a drive.
And put the quotes around the full path.
Re: Call .bat from another machine
Posted: 23 Jan 2015 08:17
by mwatsondhs
I tried cd and chdir with and without /D and it still doesn't work.
Re: Call .bat from another machine
Posted: 23 Jan 2015 08:43
by Squashman
C:\Foo.bat
Code: Select all
@echo off
setlocal enabledelayedexpansion
echo I am in the first batch file
call :rename
pause
GOTO :EOF
:rename
echo in rename function
cd /D "H:\BCS Reports\Temp"
call rename.bat
H:\BCS Reports\Temp\rename.bat
Code: Select all
@echo off
echo I am in the rename bat file.
output
Code: Select all
I am in the first batch file
in rename function
I am in the rename bat file.
Press any key to continue . . .
Re: Call .bat from another machine
Posted: 23 Jan 2015 09:00
by ShadowThief
Is P: a mapped network drive? I seem to recall something about needing to re-map the drive at the start of the script.
Re: Call .bat from another machine
Posted: 23 Jan 2015 09:26
by Squashman
If the CD command did not work you would see this as an error.
Code: Select all
The system cannot find the drive specified.
Then because the CD command did not work the CALL to the 2nd batch file would produce this error.
Code: Select all
The syntax of the command is incorrect.
Re: Call .bat from another machine
Posted: 23 Jan 2015 10:09
by mwatsondhs
Squashman,
The pause did the trick. I guess it was calling the other batch file before it got a chance to switch
directories. Thanks for all of your help. I owe you. If you ever have and SQL questions let me know.
Mark
Re: Call .bat from another machine
Posted: 23 Jan 2015 10:33
by Squashman
mwatsondhs wrote:Squashman,
The pause did the trick. I guess it was calling the other batch file before it got a chance to switch
directories.
Mark
NOT POSSIBLE.
Batch is sequential processing. It does not execute the next command until the previous command completes.
The pause was put in so you could read all the messages on the screen.
Re: Call .bat from another machine
Posted: 23 Jan 2015 12:56
by mwatsondhs
oh sorry I guess I don't know what im doing