[英]How can I set $PATH as part of spawing a process in node via node-pty?
We are trying to encapsulate a very old command-line application which has these requirements: 我们正在尝试封装一个非常老的命令行应用程序,它具有以下要求:
So the normal way to run it is to cd
to the data directory, add the application directory to the $PATH, and then run the application. 因此,运行它的通常方法是
cd
到数据目录,将应用程序目录添加到$ PATH,然后运行该应用程序。 We can't just launch the application by its full path -- the $PATH must be set because the application expects to call other sub-processes in the same directory. 我们不能只通过其完整路径启动应用程序-必须设置$ PATH,因为应用程序希望在同一目录中调用其他子进程。 We don't have the ability to modify the application or its requirements.
我们没有能力修改应用程序或其要求。
The problem is this: how do I encapsulate the setting of $PATH and the launching of the application when spawning a process in node via node-pty. 问题是这样的:当通过node-pty在node中生成进程时,如何封装$ PATH的设置和应用程序的启动。
var pty = require('node-pty');
// myapp lives in /usr/bin/app/
var term = pty.spawn("myapp", [], {
cwd: '/usr/data/mydata'
});
In short, I want the spawn to happen in the /usr/data/mydata directory, have /usr/bin/app/ added to $PATH, and myapp to get spawned, all in one shot. 简而言之,我希望生成发生在/ usr / data / mydata目录中,将/ usr / bin / app /添加到$ PATH中,并生成myapp,所有操作一次完成。
PATH is an environmental variable, so setting it with the env parameter should work. PATH是一个环境变量,因此使用env参数进行设置应该可以。
var pty = require('node-pty');
// myapp lives in /usr/bin/app/
var term = pty.spawn("myapp", [], {
cwd: '/usr/data/mydata',
env: { PATH: '/usr/data/app:' + process.env.PATH }
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.