質問

about interaction of expect and nodejs. how can send request from nodejs, to script like that:

#! /usr/bin/expect 
log_user 0
spawn -noecho ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no HOST_IP -- "some request"
expect "password: "
send "PASSWORD\r"
expect eof
send_user "$expect_out(buffer)"

i need to send a request with special parameters from nodejs, and receive it on expect side? i make a request from node in this way.

var spawn = require('child_process).spawn;
var listA = spawn('./SOME_SHELL_SCRIPT');

There is a variant to add parameters to spawn like this:

var listA = spawn('/.SOME_SHELL_SCRIPT',  args=[], [options])

how can i use that options, and take them to expect and use them there at "some request" field?

役に立ちましたか?

解決

Here's an example:

app.js

var spawn = require('child_process').spawn;

var script = spawn("./script.sh", ["A Variable"]);
var stdout= ""

script.stdout.on('data', function (data) {
  stdout = stdout + data;
});

script.on('exit', function (code) {
  console.log('stdout: ' + stdout);
});

script.sh

echo "Script Got '$1'"

trying it out:

> node app.js
  stdout: Script Got 'A Variable'
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top