[英]Use environment variable in expect spawn command
I'm trying to use expect to run a command, but with a specific set of environment variables.我正在尝试使用 expect 来运行命令,但使用一组特定的环境变量。 Here's what it looks like:
这是它的样子:
expect -c "spawn \"NODE_ENV=production node script.js\"; expect eof"
But this fails, with the following error:但这失败了,并出现以下错误:
spawn NODE_ENV=production node script.js
couldn't execute "NODE_ENV=production node script.js": no such file or directory
while executing "spawn "NODE_ENV=production node script.js""
The command works if I remove the environment variable, but I don't know how else to set it before running the command?如果我删除环境变量,则该命令有效,但在运行该命令之前我不知道如何设置它?
尝试这个:
expect -c 'spawn bash -c "NODE_ENV=production node script.js"; expect eof'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.