Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a batch file which runs as a scheduled task. For the sake of example lets call it alltasks.bat.

It looks like the following:

@ECHO OFF
clearwebtemp.bat > clearwebtemp_out.txt
clearblahtemp.bat > clearblahtemp_out.txt
clearblihtemp.bat > clearblihtemp_out.txt

This works fine when none of the called scripts change directories, but if they do then the main script fails to complete the remaining batch calls or pipe the output to the files.

I tried using the start command, but that predictably piped the output of the start command rather than that of the batch file itself.

I also tried retaining the current working directory using the %CD% variable at the top of the script and then switching back to it after each call, but the piping out to the file was done inside the directory that the script switched to, which didn't seem to make sense.

Is there an obvious (or not-so-obvious) way to achieve what I'm attempting to accomplish?

share|improve this question
    
How are you switching directories? Are you using the /d option with chdir? –  Aditya Sehgal Aug 22 '12 at 16:46
    
I am. chdir /d %OLDDIR% –  Lusitanian Aug 22 '12 at 16:53
    
Why not simply allow the scripts to change the current directory and call them by an absolute path instead, possibly containing the starting directory as a variable, i.e.: "%mydir%\foo.bat > %mydir%\bar.txt"? –  Marcks Thomas Aug 22 '12 at 17:17

1 Answer 1

up vote 3 down vote accepted

This should do what you're asking for:

cmd /c clearwebtemp.bat > clearwebtemp_out.txt
cmd /c clearblahtemp.bat > clearblahtemp_out.txt
cmd /c clearblihtemp.bat > clearblihtemp_out.txt
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.