Sg Ramkumar

Greenhorn
+ Follow
since Jun 21, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sg Ramkumar

Thanks Bill and Campbell. Perfect Answers. It worked after handling stdErr. Thanks a lot.
13 years ago
Hi, I'm executing a remote script using ssh as "Runtime.getRuntime().exec(sshcmd);". The script expects return key ass input . I've handled that using the following code. The problem is that after the execution of the script, it hangs at "pr.waitFor();". Can somebody please help me get past this issue. The same works fine if it's run without ssh.
For Info: I'm using password-less ssh


String[] cmd = {"ssh", machineName, script};

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);

OutputStream stdin = pr.getOutputStream();
String carriageReturn = "\n";
stdin.write(carriageReturn.getBytes() );
stdin.flush();
stdin.close();

BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

String line=null;
while( (line=input.readLine()) != null ) {
System.out.println(line);
}

pr.waitFor();
exitValue = pr.exitValue();
if (exitValue != 0) {
System.out.println(script + " execution failed");
break;
}
System.out.println("exitValue: " + exitValue);


Thanks
13 years ago
Hi All,

I'm using JFCUnit to automate a Swing application. There are several screens on which I'm programmatically clicking on "Next" button which takes me to the next screen.
I'm using the following code for that:

JButton myButton = (JButton)JFCTestHelper.findNamedComponent(buttonName, appWindow, index);
myButton.doClick();


The problem that I'm facing is, when I click on a non-next button of a screen, like a button when clicked, shows a popup asking for an input, I noticed that the button is not being released and so the new popup is not gaining control, because of which I'm not able to provide the input on the popup

Can somebody please help me on this with a small piece of code.

Thanks.
13 years ago
Thanks guys for the answers. It was greatly helpful.

I used the following code:

try {
Runtime rt = Runtime.getRuntime();
String[] cmd = {"/bin/bash", "-c", "myscript.sh"};
System.out.println("Command to execute: " + cmd);
Process pr = rt.exec(cmd);
System.out.println("Pausing 10 sec...");
Thread.sleep(10000);
System.out.println("Pausing 10 sec... done");
OutputStream stdin = pr.getOutputStream();
String carriageReturn = "\n";
stdin.write(carriageReturn.getBytes() );
stdin.flush();
stdin.close();

BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

String line=null;

while((line=input.readLine()) != null) {
// System.out.println(line);
}

int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);

} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
13 years ago
Hi,

I'm having a shell script that is to be invoked from a java program.
The shell script is like:
# /tmp/a.sh
#!/bin/sh
read a
echo "this is the next line"


I want the java program to execute this shell script without prompting for "enter key" to be pressed

String commandToExecute = "sh /tmp/a.sh";
Process p = Runtime.getRuntime().exec(commandToExecute);

The above 2 lines are part of my java program. Executing the above java code hangs waiting for input.
Need help on getting the java code lines to automatically accept enter key and go next on the shell script
13 years ago