This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I'm using CCS V5.1 scripting to start debugging sessions, connect to target, re-load program, etc. After the program is rebuilt, I'd like to be able to make some system calls, essentially the same effect as the "system()" call in the C language. Is there a way to do this?
Regards,
Robert
Hi Robert,
You can use the java.lang.runtime functions for this:
http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frzaha%2Fjavalang.htm
There are some gotcha you need to be aware of when using it though. Hence I created a little include javascript you can include and make the calls to the wrapper functions that will then call the runtime functions. Just include the attached script to your main script and then create the runtime object and use the runSynch or runAsynch calls to make system calls. Below is an example:"
var rt = new Runtime();
// call a system command
ret_val = rt.runSynch("dir");
Thanks
ki
I forgot to attach the script. Here it is (rename with *.js extension)
// RuntimeJava.js // Java runtime implemetation function streams(proc) { var stdin = proc.getInputStream(); var isr = new java.io.InputStreamReader(stdin); var br = new java.io.BufferedReader(isr); var line = null; while ( (line = br.readLine()) != null) print("> " + line); } // Synchronous run function RunSynch(cmd) { var rt = new java.lang.Runtime.getRuntime(); print("> " + cmd); var proc = rt.exec(cmd); streams(proc); var exitVal = proc.waitFor(); return exitVal; } // Asynchronous run function RunAsynch(cmd) { var rt = new java.lang.Runtime.getRuntime(); print("> " + cmd); var proc = rt.exec(cmd); streams(proc); //return exitVal; } // Constructor for file system access function Runtime() { this.runSynch = RunSynch; this.runAsynch = RunAsynch; }
Hello,
I wasn't able to complete this, and came back to it today. I saved your file (as RunTime.js), and did this in my js file:
load( "project_path/RuntimeJava.js" );
I then did a simple "dir" test that fails. Here is the test:
function test()
{
var rt = new Runtime();
ret_val = rt.runSynch( "dir" );
print( "ret_val" );
}
CCS reports back the following error, when I try to run test:
js:> test
> dir
Wrapped java.io.IOException: Cannot run program "dir": CreateProcess error=2, The system cannot find the file specified (project_path/RuntimeJava.js#22)
Please advise,
Robert
after further investigation, this change to the runSynch() line made it work (under Win 7):
ret_val = rt.runSynch( "cmd /c dir" );
;)
Robert