Groups
Groups
Sign in
Groups
Groups
Yet another Expect for Java
Conversations
Labels
About
Send feedback
Help
Runas command execution. Password is not accepted.
22 views
Skip to first unread message
Max Cooper
unread,
Sep 15, 2022, 9:11:51 AM
9/15/22
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Yet another Expect for Java
Hi, all!
RunAs commad opens own InputStream and I can't figure out how to send password
String runas = "runas /noprofile /netonly /user:LOGIN \\\"ping 8.8.8.8\\\"";
String pass = "PASSWORD";
try {
ProcessBuilder processBuilder = new ProcessBuilder();
process = processBuilder
.redirectErrorStream(true)
.command(Arrays.asList("cmd"))
.start();
StringBuilder wholeBuffer = new StringBuilder();
Expect expect = new ExpectBuilder()
.withOutput(process.getOutputStream())
.withInputs(process.getInputStream())
.withEchoOutput(wholeBuffer)
.withEchoInput(wholeBuffer)
.withExceptionOnFailure()
.build();
expect.expect(contains(">"));
expect.sendLine(runas);
expect.expect(contains("nter the password for"));
expect.sendLine(pass);
String response = wholeBuffer.toString();
System.out.println(response);
expect.close();
}
Reply all
Reply to author
Forward
0 new messages