duananyu9231 2011-12-23 21:07
浏览 28
已采纳

触发节点js文件

I have a JS file that runs via node.js, so normally I crank open a terminal window and type something like node myfile.js and it runs and runs all day; fun.

Then when I want to reboot it, I hit control-c and and it quits. Then I can run the command again.

Now what I would like to do is be able to do this through a web page so that my users can run specific JS files and also be able to "reboot" them.

So two questions about this:

  1. Is it possible, and if so how do I get started?
  2. Is it safe, and if not, can it be made safe?

Based on swatkins response

i tried this and got nothing

 $output = exec("node -v");
 echo $output;

then i tried on my local machine and it worked fine what gives ?

also I'm still not sure about the security and the ability to stop a running script

  • 写回答

2条回答 默认 最新

  • duanfu1873 2011-12-23 21:21
    关注

    Assuming you're on Unix-based OS:

    You can run shell commands via the exec() function:

    // in php file
    // to start the script 
    exec("node myscript.js &", $output);
    

    $output becomes an array of each line of output, so you can see what the process id is. Then you would use that process id to kill the script:

    exec("kill " . $processid);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题