0

I have the following problem. I got a bat file that runs testcomplete test. After the test is finished in testcomplete, the app closes and exit code is passed back to the bat. Still in bat file i create a txt file called result and then depending on exit code i write to it successs, failure etc. When i run that bat file in Windows 7 i can see that test is being executed and after it's finished result.txt file appears with information i need. But when i simply run this same bat file from java code:

Process p1 = Runtime.getRuntime().exec(batch);

after the test is finished, file does not appear. Is there any way to get this to work fine? What should i change?

Script code is more less like that:

@ECHO OFF
"...\Bin\TestComplete.exe" "sometext.pjs" /r 
/p:sometext PathToApp="sometext.jnlp" Login=ads Password=ass  /t:"sometext|sometext" /exit 
IF ERRORLEVEL 3 GOTO CannotRun
IF ERRORLEVEL 2 GOTO Errors
IF ERRORLEVEL 1 GOTO Warnings
IF ERRORLEVEL 0 GOTO Success

:CannotRun
ECHO The script cannot be run >> "result.txt"
GOTO End

:Errors
ECHO There are errors >> "result.txt"
GOTO End

:Warnings
ECHO There are warnings >> "result.txt"
GOTO End

:Success
ECHO No errors >> "result.txt"
GOTO End

:End
Arek
  • 1,941
  • 4
  • 22
  • 27

2 Answers2

0

I would guess that you need to specify your Working Directory, by using an overloaded version of exec:

exec(String command, String[] envp, File dir)

Peter Lang
  • 54,264
  • 27
  • 148
  • 161
  • Thx for answers. But there's another issue right now. I did that to get the txt file with result of test run. Now from my code i would like to wait until the but run is finished. I do that by looping until the file called result.txt exists. Not the nicesest solution i guess but i thought it could work. What happens is that it will loop fine and wait until file exists, but the parameters i send to testcomplete don't get there. It seems like they're just coming to the app, cause me inputs in tested app don't fill in. When i run it without any waiting done in code, everything is fine. – Arek Jul 28 '11 at 10:52
  • 2
    @Arek: I'm not sure if I understand what you mean, but if your original problem is solved, then try asking another question, describing the new problem. – Peter Lang Jul 28 '11 at 13:27
0

Another thing is, that you should always read the InputStream of the process. If you don't the process might hang.

DoubleMalt
  • 1,263
  • 12
  • 17