1

I have an Express Node.js application, but I want to run a machine learning python codw with a following command.

I already find some online solutions to run python machine learning code.With this stackoverflow link How to call a Python function from Node.js

But with this solution I just run run a python code.

var spawn = require("child_process").spawn;
      var process = spawn('python', ["./my_script.py"]);
      process.stdout.on('data', function (data) {
        res.send(data.toString());
      })

With this code I just run a code python hello.py .But I want to run a code with following commands python test.py --model dataset/test.model --image s.jpg

1 Answer 1

1

You can use python-shell

import {PythonShell} from 'python-shell';

const options = {
            args: [
                '--image',
                's.jpg'
            ]
        };

PythonShell.run('script.py', options, (err, results) => {
  // your code 
});

If you want to use spawn you can do somthing like this:

const args = ['script.py', '--image', 's.jpg'];
const process = spawn('python', args);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.