Support the ongoing development of Laravel.io →
posted 11 years ago
Requests

Hi,

I'm trying to execute a Python script from my Controller. In my controllers directory I created a folder called pythonScripts in which I have placed my script. From my controller function I am getting data from the database, in json format, and passing it to python to create a network and then do some analysis on the network using networkx. The problem is that i'm unable to execute the script. The following is my code for runing the script.

$output = array();
    exec("/pythonScripts/createNetwork.py '{$connections}' ", $output);
    return json_encode($output);

in the python script, at the moment, i'm only printing out whatever is passed in to see if the script is being executed but in return I get an empty array []. The following is my python script.

import json
import networkx as nx 
import sys
from networkx.readwrite import json_graph


def main():
    userJSONData = sys.argv[1] #the JSON format of user data will be passed into this script.
    
        print userJSONData


if __name__ == '__main__':
    main()

I can't tell if the script is executing ... any help? PS: I don't know which category to put this in so correct me if im wrong :)

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Haseeb90 haseeb90 Joined 8 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.