Topic
  • 9 replies
  • Latest Post - ‏2016-10-14T14:49:02Z by DarshanAC
SystemAdmin
SystemAdmin
3180 Posts

Pinned topic Executing python scripts using dxl

‏2012-10-22T04:49:50Z |
Hello,

Is it possible to execute python scripts from within dxl scripts? If so, how?

-Neeraja.
Updated on 2012-10-22T14:36:54Z at 2012-10-22T14:36:54Z by Mathias Mamsch
  • Mathias Mamsch
    Mathias Mamsch
    2393 Posts

    Re: Executing python scripts using dxl

    ‏2012-10-22T14:36:54Z  

    did you try:
     

    system("python.exe myscript.py")
    

     

    ? Maybe this helps, regards, Mathias

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

     

    Updated on 2014-01-06T15:07:11Z at 2014-01-06T15:07:11Z by iron-man
  • DarshanAC
    DarshanAC
    4 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-13T15:43:08Z  

    Hello Mathias,

     Can I pass dxl string in this system() command..?

    Thanks,

    Darshan

  • Mathias Mamsch
    Mathias Mamsch
    2393 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-14T07:10:05Z  

    Hello Mathias,

     Can I pass dxl string in this system() command..?

    Thanks,

    Darshan

    Yes. Did you try?

  • DarshanAC
    DarshanAC
    4 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-14T07:35:01Z  

    Yes. Did you try?

    Yes I tried passing string in system() command, but it is not working. Actually I need to make python code dynamic based on the dxl string value.
     

    below is the command I am using in dxl to cal python file.

    system("C:\\ismPython\\V3_2\\python.exe C:\\Users\\CDH4ABT\\Desktop\\Data\\CLAuDIA\\out\\Intermediate_File.py")

     

    I have a string named 'abc', I need to pass this string via above system() command, because code in python is dependent on sting value.

    below is the command where I pass string 'abc'. but its not working.

    system("C:\\ismPython\\V3_2\\python.exe C:\\Users\\CDH4ABT\\Desktop\\Data\\CLAuDIA\\out\\Intermediate_File.py abc")

     

    Regards,

    Darshan

  • Mathias Mamsch
    Mathias Mamsch
    2393 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-14T10:36:46Z  

    Yes I tried passing string in system() command, but it is not working. Actually I need to make python code dynamic based on the dxl string value.
     

    below is the command I am using in dxl to cal python file.

    system("C:\\ismPython\\V3_2\\python.exe C:\\Users\\CDH4ABT\\Desktop\\Data\\CLAuDIA\\out\\Intermediate_File.py")

     

    I have a string named 'abc', I need to pass this string via above system() command, because code in python is dependent on sting value.

    below is the command where I pass string 'abc'. but its not working.

    system("C:\\ismPython\\V3_2\\python.exe C:\\Users\\CDH4ABT\\Desktop\\Data\\CLAuDIA\\out\\Intermediate_File.py abc")

     

    Regards,

    Darshan

    If you have a variable named "abc", then you need to append it to the string, otherwise you will only pass the literal "abc" ... I would have thought that might be obvious! e.g. 

    string myQuote (string s) {
        return s; // you should quote your strings before you pass them over the commandline!
        // You need to implement this function, if you need it.
    }
    
    string abc = "Hallo"; 
    system("C:\\ismPython\\V3_2\\python.exe C:\\Users\\CDH4ABT\\Desktop\\Data\\CLAuDIA\\out\\Intermediate_File.py " (myQuote abc))
    

    Hope this helps, regards, Mathias

    Updated on 2016-10-14T10:37:10Z at 2016-10-14T10:37:10Z by Mathias Mamsch
  • DarshanAC
    DarshanAC
    4 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-14T10:42:23Z  

    If you have a variable named "abc", then you need to append it to the string, otherwise you will only pass the literal "abc" ... I would have thought that might be obvious! e.g. 

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">string myQuote (string s) { return s; // you should quote your strings before you pass them over the commandline! // You need to implement this function, if you need it. } string abc = "Hallo"; system("C:\\ismPython\\V3_2\\python.exe C:\\Users\\CDH4ABT\\Desktop\\Data\\CLAuDIA\\out\\Intermediate_File.py " (myQuote abc)) </pre>

    Hope this helps, regards, Mathias

    Thank you very much Mathias.

    Is there any possibility that I can get the result of python file, so that I can use that result in dxl script. ?

  • Mathias Mamsch
    Mathias Mamsch
    2393 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-14T11:01:39Z  

    Thank you very much Mathias.

    Is there any possibility that I can get the result of python file, so that I can use that result in dxl script. ?

    You shoud pass in the name of a temporary file to which the python script stores its output. Then you read the file from DXL after the python finishes. Regards, Mathias

  • Mathias Mamsch
    Mathias Mamsch
    2393 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-14T11:03:46Z  

    You shoud pass in the name of a temporary file to which the python script stores its output. Then you read the file from DXL after the python finishes. Regards, Mathias

    By the way, there is a "shell" class inside the DXLParallels tutorial, which you can use: 

    https://github.com/domoran/DXLParallels/tree/master/lib/core

    It will allow you to read the output of a process, get its exit code, etc. Examples are inside the file. Regards, Mathias

  • DarshanAC
    DarshanAC
    4 Posts

    Re: Executing python scripts using dxl

    ‏2016-10-14T14:49:02Z  

    Hi Mathias,

     

    Thank you very much for your valuable response.