Call python script from ruby

前端 未结 5 1555
一整个雨季
一整个雨季 2020-12-14 20:40

For example, I can use Python scripts in PHP like there:

exec(\"python script.py params\",$result);

where \"script.py\" - script name and v

相关标签:
5条回答
  • 2020-12-14 21:00

    You can shell-out to any shell binary and capture the response with backticks:

    result = `python script.py params`
    
    0 讨论(0)
  • 2020-12-14 21:07

    I used the following python call from a ruby module.

    In my case using exec() didn't work because it interrupts the current process and caused the simulation I was running to fail.

    # run python script
    `python #{py_path_py} #{html_path_py} #{write_path_py}`
    
    0 讨论(0)
  • 2020-12-14 21:07

    You can use backticks to accomplish this in two ways

    result = `python script.py params`
    

    or

    result = %(python script.py params)
    
    0 讨论(0)
  • 2020-12-14 21:17

    Another way to do the same thing would be,

    system 'python script.py', params1, params2
    
    0 讨论(0)
  • 2020-12-14 21:23

    One way would be exec.

    result = exec("python script.py params")
    
    0 讨论(0)
提交回复
热议问题