start node app from python script

前端 未结 2 737
梦如初夏
梦如初夏 2021-01-02 23:06

Is it possible to start a node.js app from within a python script on a raspberry pi?

On the command line I run sudo node myscript.js

could I use

2条回答
  •  鱼传尺愫
    2021-01-02 23:34

    The first line of file shall be:

    #!/usr/bin/python
    

    You can call command with subprocess.call:

    from subprocess import call
    
    # Note that you have to specify path to script
    call(["node", "path_to_script.js"]) 
    

    Then you have to set +x permissions for file to be executable:

    chmod +x filename.py
    

    Know you are ready to go:

    ./filename.py 
    

    Note: checkout Raspberry Pi Stack Exchange, you can find a lot of use full info there.

提交回复
热议问题