dimanche 5 décembre 2021

Executing python file within another python file using Laravel

I'm currently calling the main python file in larval function, and inside that main python file I'm calling another 2 files ( PowerShell and sub python file) the problem is when the Laravel function is triggered it only call the main python file, however when I call the main python file using terminal all the files are executed like below:

Laravel function:

public function initialize(Request $request)
{
    $store_name = $request->get('store_name', 1);
    if (empty($store_name)) {
        return 'Missing store name';
    } else {
        $processes = File::get("/root/flask/android_api/processes.txt");
            File::put('/root/flask/android_api/url.txt', $store_name );
            $process = new Process(['python3.6', '/root/flask/android_api/buildAPK.py']);
            $process->run();
            if (!$process->isSuccessful()) {
                    throw new ProcessFailedException($process);
            } else {
                    return 'Starting the processes to build';
            }   
    } 
}

and within the main python file I have:

try:
    p = subprocess.Popen(["/usr/bin/pwsh", 
            "/root/flask/android_api/set_apk_builder.ps1", '-ExecutionPolicy',
                        'Unrestricted',
                        './buildxml.ps1'], 
            stdout=sys.stdout)
    p.communicate()

except:
    file = open ("/root/flask/android_api/log.txt", "w")
    file.write ("fail")
    file.close()


import slack
call(["python", "/root/flask/flask.py"])
os.system('python3.7 /root/flask/flask.py')


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3orJETu
via IFTTT

Aucun commentaire:

Enregistrer un commentaire