linux - Take commands(password) from string and set as InputStream to Unix servers in Java (JSCH) -
almost similar this topic, here not superuser use --stdin.
so found other way round, open "shell" in background , give input shell via string
through inputstream
i made code below:
string s = "cd bin\n"; byte bb[] = s.getbytes(); inputstream intt = new bytearrayinputstream(bb); channel.setinputstream(new filterinputstream(intt) { public int read(byte[] b, int off, int len) throws ioexception { return in.read(b, off, (len > 1024 ? 1024 : len)); } });
now works when want execute 1 command want give multiple commands, facing issue.
any suggestions?
regards,
ishan
i found solution question asked, don't know if full proof solution since tested limited period of time , did beast way can.
channel = session.openchannel("exec"); ((channelexec) channel).setcommand(command); ((channelexec) channel).setpty(true);
in command string
string command = "(echo old_password; echo new_password; echo new_password) | passwd username";
or if not superuser then,
string command = "(echo old_password; echo new_password; echo new_password) | passwd"
that ;)
regards,
icr
Comments
Post a Comment