Runas command execution. Password is not accepted.

22 views
Skip to first unread message

Max Cooper

unread,
Sep 15, 2022, 9:11:51 AM9/15/22
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