【发布时间】:2017-12-10 05:07:34
【问题描述】:
我有一个在 Windows Server 上运行的 MEAN (Angular 2) 应用程序。 我在服务器上使用 iisnode 运行我的应用程序。 该应用程序运行良好,但有时我尝试使用节点(powershell.exe)生成一个子进程。在本地一切正常(powershell 脚本成功执行),但是当我从服务器 URL 测试它时,子进程永远不会产生。 我没有任何错误消息,该应用程序只是有点暂停。 当我使用“node server.js”从命令提示符运行 node.js 并转到:http://myserver.com:9000 时,应用程序运行良好,子进程成功生成。
我试过放powershell.exe的绝对路径,但是也没用。
localhost:9000 : 应用工作,子进程生成 ans 工作正常
myserver.com:9000 :应用工作正常,子进程生成 ans 工作正常
myserver.com/:应用程序正常,子进程不会产生,没有错误消息
这是我的 web.config 文件:
<configuration>
<system.webServer>
<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="server">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这是我生成子进程的route .js:
child = spawn("powershell.exe",[`some commands`]);
child.stdout.on("data",function(data){
console.log("Powershell Data: " + data);
});
child.stderr.on("data",function(data){
console.log("Powershell Errors: " + data);
});
child.on("exit",function(){
console.log("Powershell Script finished");
//some other commands
});
child.stdin.end();
【问题讨论】:
标签: node.js powershell child-process windows-server iisnode