Skip to main content
Known Participant
August 30, 2018
Answered

How to get the result of a Python script

  • August 30, 2018
  • 1 reply
  • 3769 views

Hi,

I need to get some data by executing a Python script from a JS script that would be then used by that same JS script.

Any idea on how I could get the result of an executed Python script? Or any advice of what would be the best approach for doing this?

Thanks,

Jeremy

This topic has been closed for replies.
Correct answer r-bin

I'll definitely try to pass a string at first indeed to see if I can get the result at least.

But then, the idea is to get a dictionary of data I will request from a database, so I'll also need to find out how the file.execute() of the Python script is completed and that's why I created this thread hoping that someone could help on this.


// file = your bat file

file.execute();

//At the end of the Python script execution, you must remove the bat-file from the command in the bat-file itself or in the Python script.

var ok = false;

try {

    while (1)

        {

        if (!file.exists) { ok = true; break; }

        set_performance("stepByStep");

        }  

    }

catch(e) { }

set_performance("accelerated");

if (!ok) throw("Error") ;

// in C:/PATH/result_file, your Python script should write some code in js format.

// for example

// var data1 = 1.234;

// var data2 = [1.234, 2345, 5,6];

// var data3 = ["string1", 2345, false];

$.evalFile("C:/PATH/result_file");

File("C:/PATH/result_file").remove();

// Now you can use data1, data2 and data3 in your jsx script

function set_performance(mode)

    {

    try {

        var d1 = new ActionDescriptor();

        var d2 = new ActionDescriptor();

        var r1 = new ActionReference();

        r1.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "PbkO" ) );

        r1.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

        d1.putReference( charIDToTypeID( "null" ), r1 );

        d2.putEnumerated( stringIDToTypeID( "performance" ), stringIDToTypeID( "performance" ), stringIDToTypeID( mode ) );

        d1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "PbkO" ), d2 );

        executeAction( charIDToTypeID( "setd" ), d1, DialogModes.NO );

        }

    catch (e) { throw(e); }

    }

1 reply

Legend
August 30, 2018

How do you run a Python script from a JSX file? I do not know anything about Python scripts. If you can set some environment variable in Python, then you can try to read it in JSX script using $.getenv().

Known Participant
August 31, 2018

I write the command ('python python_file_path args') into a bat file that I run with the file.execute() method.

I already did that for other scripts and this works well but I'm looking for a way to get the result of the Python script.

I could try the environment variable approach but I'm not quite sure if I would be limited in the type of data I could set it with.

Legend
August 31, 2018

You first try to pass at least a string.
And the question. How do you find out in the script that Python completed the job if you use file.execute() ?