2

I have a batch file that first creates another batch file containing a ClearCase cleartool command and second, runs it:

ECHO cleartool lsactivity -long "%ACTIVITY%"^>"%OUTPUTFILE%">FILETORUN.bat
CALL FILETORUN.bat

When running the batch, FILETORUN.bat is generated with the correct format, but the CALL to it is completely ignored.

If I ECHO output after the CALL to a log file, I can see that the script just skips over it.

What could it be?

I have tried removing CALL but it makes no difference.

EDIT: SOLUTION

Thank you all for the input. I found the problem. Before the write to batch and batch call in the script there was a command that read information into a variable from a file:

SET /p FILETODELETE=<rmname_%CLEARCASE_USER%.tmp

It reads only the first line. For some reason this created a conflict with temporary batch file, and I have no idea why. I used a different solution for reading the first line from a file and the conflict doesn't happen anymore:

(set FILETODELETE=)
for /f "delims=" %%q in (rmname_%CLEARCASE_USER%.tmp) do if not defined FILETODELETE set FILETODELETE=%%q

If anyone can shed some light it would be great!

Andrew
  • 293
  • 6
  • 14
  • Are you sure FILETORUN.bat is not being called? Or does it simply not do what you think it should do? Try commenting out the echo line, writing FILETORUN.bat manually (just make it echo something), and convince yourself it really isn't running at all. – Nate Hekman Feb 26 '13 at 16:03
  • Perhaps you need to include the path: `CALL "%OUTPUTFILE%\FILETORUN.bat"`? – Nate Hekman Feb 26 '13 at 16:04
  • You say it doesn't run - is it simply that `cleartool lsactivity` only returns an error (which it will if you're not in your view), which would not get redirected to the output file? You could try redirecting stderr to a file (add `2>&1` into your generated batch file, which will redirect errors too - you'll need to escape the `>`) and see if that gives you any hints. – icabod Feb 26 '13 at 17:51
  • @NateHekman Hi Nate. I tried to run the bat using the complete path but it makes no difference. I also tried adding a new line: `ECHO ECHO TEST^>TEST.TXT>TEST.BAT` followed by `CALL TEST.BAT` and that works. The strange thing is that the `cleartool` batch above works with a ClearCase checkin operation but not with a ClearCase delete operation (the scripts are triggers). The only difference is that the latter case has another script running just before the one that invokes cleartool. Is there a way of exiting that first batch appropriately? I currently use `EXIT /B` as the last line. – Andrew Feb 26 '13 at 17:55
  • @icabod Hi icabod. The `cleartool lsactivity -long` command outside of a view context returns basic activity info such as headline, owner, or stream without the changeset, which is all I need. As I mentioned to Nate, the batch works fine with ClearCase checkin operations, but not with delete operations. Also, once the bat file is generated (and not run), I can just double click on in from Windows Explorer and it will generate the file I need. It's very strange behaviour! – Andrew Feb 26 '13 at 17:58
  • @NateHekman Hi again Nate. As an update to your first note, I hardcoded the bat that was generated and not run in a previous attempt into the script using `CALL .bat` and it works. The script doesn't seem to want to run it as soon as it is generated. – Andrew Feb 26 '13 at 18:18
  • That's strange, I can't see why that would be. But taking a step back, do you have to write `cleartool etc` to a batch file and run the batch file? Could you not just run cleartool directly? – Nate Hekman Feb 26 '13 at 19:19
  • @NateHekman I wish I knew what was going on! If I remove the intermediate batch file I would end up with my previous problem [here](http://stackoverflow.com/questions/14998729/cmd-batch-file-calling-cleartool-command-freezes-script-when-writing-to-file) which I seem to have managed to solve. Unfortunately this approach causes this non-execution problem. – Andrew Feb 26 '13 at 19:21
  • Try adding `ECHO pause>>FILETORUN.bat` to see if any error messages appear? – AjV Jsy Feb 26 '13 at 19:47
  • Thank you all for the input. I found the problem. Before the write to batch and batch call in the script there was a command that read information into a variable from a file: `SET /p FILETODELETE= – Andrew Feb 26 '13 at 20:12
  • Try putting an @ symbol in front of the SET or the CALL. If it doesn't fix it, can you redo the question since I'm not 100% clear on what's working and what isn't, though "@" has fixed an issue that looks similar to me... – Lizz Mar 01 '13 at 01:30
  • 2
    You should mark this as solved – rud3y Mar 08 '13 at 15:04

1 Answers1

0

SET /P waits for user input, so it actually will finish the command with what you are trying to execute after that and consume the input buffer, which might produce different results on each machine. See set command reference for more details

Efren
  • 4,003
  • 4
  • 33
  • 75