dsxay48646 2015-12-05 18:32
浏览 363

在一个命令提示符窗口中启动多个长时间运行的后台进程?

All I want is to start a bunch of background processes from the shell. That's all.

Here's what I have in a batch file called start_servers:

@ECHO OFF
call setenv
START "" /B xampp\apache_start.bat
START "" /B xampp\mysql_start.bat
START "" /B php start_daemon.php
echo Server started

when I run this by double clicking the batch file, it all works fine. I get the output of all 3 processes in 1 window. However, if I start the shell in the same directory, type in 'start_servers.bat' and hit enter, it runs apache_start and mysql_start just fine, but the php script 'start_daemon' seemingly doesnt run, but I get 'Server started' outputted.

The weirdest thing though is If I hit enter once more, then php start_daemon.php runs! It's as if 'php start_daemon.php' is being typed on my keyboard, but it's invisible to me. When I hit enter, it appears like so:

[cwd]> start_servers.bat
...

[cwd]>Websocket Server started
Listening on: 0.0.0.0:9000
Master socket: Resource id #7

Notice the part '[cwd]>Server started' like I entered it as a command.

I've spent a whole day trying to work this out, It's driving me crazy!!!!!

Please please please help.

EDIT:

I've just been trying some other things and I'm still getting the same damn result. If I reduce the .bat down to 'START "" /B php start_daemon.php' or if I simply type it into the commandline, I get the same result. First return, nothing. Second return, it runs.

I've also tried the following:

START "" /B node test.js

result:

C:\Users\hedge\Projects\PHPStorm\gpstudios>this is a test

what I expect:

this is a test
C:\Users\hedge\Projects\PHPStorm\gpstudios>

Also:

START "" /B python2 test.py

result:

C:\Users\hedge\Projects\PHPStorm\gpstudios>this is a test

And finally:

START "" /B python3 test.py

result:

C:\Users\hedge\Projects\PHPStorm\gpstudios>   [nothing, I hit return]
C:\Users\hedge\Projects\PHPStorm\gpstudios>   [nothing again, I hit return]
C:\Users\hedge\Projects\PHPStorm\gpstudios>this is a test

What on earth is going on? They all output the result to the line where I type my commands, which i suppose makes sense as the terminal is not waiting for the START call to finish before handing control back to me, however, PHP scripts require I hit return once more, and a Python3 script requires 2 returns! This is not at all intuitive. Again, I plead for help. This is killing me.

EDIT 2:

If I run 'START "" /B /WAIT php start_daemon.php' or 'php start_daemon.php' then obviously, the script runs immediately and as expected, but it then freezes the shell and requires I start a new one in order to input any further commands. I plan on running more than one background processes via node or php, but as it is I can only run one in a single CMD terminal.

I'm just trying to rephrase the problem a little in hope of getting some replies, if that helps...

  • 写回答

3条回答 默认 最新

  • doupapin172773 2015-12-05 19:50
    关注

    Did you try to put a temporisation before starting the PHP script ?

    @ECHO OFF
    call setenv
    START "" /B xampp\apache_start.bat
    START "" /B xampp\mysql_start.bat
    timeout 5 >nul
    START "" /B php start_daemon.php
    echo Server started
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)