var spawn = require("child_process").spawn;
var child = spawn("scp" , ["-P9022", path_to_file, scp_remote_path])
child.stdout.on("data", function(){
//Automatically type in password
})
I'm trying to scp into a remove server and automate password entry (I know, I should be using public key auth instead, but that's besides the point). When I run the code shown I get the right password prompt; is there anyway I can detect the presence of said prompt through code? The "data" event doesn't seem to be triggered in this case.
Edit: Not sure if this matters, but process.stdout.isTTY is true. Of course I then tried listening on the readable event for process.stdin like so
process.stdin.on "readable", ()->
buf = process.stdin.read()
buf2 = process.stdout.read()
console.log "pin", buf, buf2
The callback gets called but both buf and buf2 are null
Streams have changed in node 0.10 which might be the reason for the event not firing. In theory, adding adding a "data" event listener should switch the readable stream into a backwards compatible mode. However, at the point where you start listening to the "data" things might be in a certain state already. (that's my theory, I might be completely wrong in this)
With the new readable streams in node 0.10 you should not listen for the "data" event but instead listen for the "readable" event and then read data from the stream. See here for more info readable event
try this:
child.stdout.on("readable", function(){
var buf = child.stdout.read();
// check that you got your complete prompt for password...
// write password to stdin...
});