简体   繁体   中英

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. 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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM