Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

Run python script with args in javascript with exec

$
0
0

I have inputs such as latitude, longitude and frequency. I would like to run this command on a JS file :

exec(`python test.py '{"latitude":${latitude},"longitude":${longitude},"frequency":${frequency}}'`, (error, stdout, stderr) => { .... })

But when I run I have the following error :

error: Command failed: python test.py '{"latitude":48.118097,"longitude":-1.636503,"frequency":2.4}'
Traceback (most recent call last):
  File "test.py", line 16, in <module>
    data=json.loads(sys.argv[1])
  File "C:\Users\****\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\****\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\****\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

And my python script begin with

import sys
import json
data=json.loads(sys.argv[1])

Moreover if I just run my python script without args, and write random data directly in the python script, it works. So I think it's a problem of the args written in the exec command.

Can you please help me.


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>