windows - Syntax error on running a batch file to replace files

18
2014-05
  • Ralph

    I have a batch file intended to replace all instances of tracking.js within a folder/sub folders.

    FOR /R "D:\Virtual Servers (Testing)\CourseWare Master\Shared\Jenison\Version1.2\" %%I IN (tracking.js*) DO COPY /Y "D:\Virtual Servers (Testing)\CourseWare Master\Shared\Jenison\tracking.js" %%~fI

    When this is run I get the following syntax error

    C:>COPY /Y "D:\Virtual Servers (Testing)\CourseWare Master\Shared\Jenison\track ing.js" D:\Virtual Servers (Testing)\CourseWare Master\Shared\Jenison\Version1.2 \SHAPERS_COMBINED\Smarter Communications\WhatisInfluencing\script\Tracking.js The syntax of the command is incorrect.

    Ideas please?

  • Answers
  • Bali C

    I think you need to quote %%~fI as it expands to a path with spaces.

    FOR /R "D:\Virtual Servers (Testing)\CourseWare Master\Shared\Jenison\Version1.2\" %%I IN (tracking.js*) DO COPY /Y "D:\Virtual Servers (Testing)\CourseWare Master\Shared\Jenison\tracking.js" "%%~fI"
    

  • Related Question

    windows - Running batch file through a service
  • wallz

    I'm trying to schedule a batch file to run through a third party application, however the output file doesn't get created in the directory. If I run the .BAT file from the command line, it works and the file gets created. Also using the Windows Schedule will also succeed.

    Basically, the 3rd party software will schedule the .BAT file and it shows success within the 3rd party user interface. The difference between running from the command prompt and the software, is that the software will use its Windows service to launch the batch.

    The 3rd party software will show success since it was able to successfully call the .BAT file to run, however it has no control of the other EXE's that's being called within the script.

    I'm able to run a simple .BAT file in the 3rd party software, for example a copy command.

    The .BAT I'm having problems with calls a compiled EXE which launches Excel to create a file to a location.

    The .bat file calls something.exe, which then calls Excel.exe:

    C:\something.exe -o D:\filename.xlsm C:\filename.xlsm refresh_pivot

    Do you think it's a permissions issue? I used Process Monitor to verify any Access Denied errors but everything seems to be working according to the trace. It worked on a non-64-bit OS, I'm currently using Win2008 64-bit.


  • Related Answers
  • afrazier

    What user credentials is the Scheduled Task running under? Has Excel been run and configured under that user account? My gut says that's where things are falling down -- Office hasn't been through its first run on the account running the batch file.

  • Diffuser

    Afrazier is probably on the right track. You can test this by using the runas command from the command prompt and test running the batch file with the same account that the service uses. This would be a much better test than simply running the batch file from the command prompt under your user account or administrator.

    The command would look something like this: C:\> runas /user:DOMAIN\service_acct "scheduled.bat"

    I would also try substituting the actual something.exe command for the batch file and see if that has any different output, ie- C:\> runas /user:DOMAIN\service_acct "something.exe -o D:\filename.xlsm C:\filename.xlsm refresh_pivot"

    That might give you a better understanding of what is going on. If an access denied error happens then it's definitely a permissions thing. You can try just typing runas at the prompt to see other options as well.