Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Execute Client Program with ST

2017-12-14
2021-05-19
  • BrotherMaestro - 2017-12-14

    Hello Team.

    I've spent the day reading through the forums to seek a solution to my problem.
    Perhaps I have missed something obvious which is why a solution eludes me...

    I'm trying to run an executable file through my program POU.
    This is what I've done so far.

    CODESYSControl.cfg
    [SysProcess]
    Command=AllowAll
    [SysFile]
    Windows.WorkingDirectory=C:\ProgramData\CODESYS\CODESYSControlWinV3x64\801BFF8C
    

    AND

    Β 
    Β command1 : STRING := 'C:\OpenGL\GUIproject\Release\GUIproject.exe'
    
    IF xExecuteSysP THEN
    Β  Β xExecuteSysP := FALSE;
    Β  Β (*SysProcess.SysProcess Execute Command( pszComand:= command1,Β  pResult := ADR(Result));*)
    Β  Β SysProcess.SysProcessCreate(pszApplication := command2, pszCommandLine := command1, ulHide := 0, pResult := ADR(Result) );
    END_IF
    

    PS: I made a button to launch the executable through the visualization and that works, so the file and the path are fine. I get no compile errors either and the rest of the program seems to run fine.
    I'm working on Windows 7, in a simulation as I do not have access to a device just yet.
    Note: The commented solution did not work either.

     
  • eschwellinger

    eschwellinger - 2017-12-14

    Hi,
    why not using the installed Control Win runtime?

    BR
    Edwin

    IMG: Control Win.jpg

     
  • BrotherMaestro - 2017-12-19

    Thank you kindly for your response!
    This was the obvious flaw in my program that I failed to understand.

    In hindsight it makes perfect sense that to perform commands you
    need to be logged into a device....

    Everything is working now. Thank you again.

     
  • alien - 2021-05-19

    Hi @eschwellinger,

    I hope you read my message! I am in S.O.S situation indeed . .
    Actually, I have a big problem may be you can help me :
    I am working on Windows 10 x64 and I need to execute a batch file in CodeSyS for some purpose
    but SysProcess Execute Command is not working ! I have done these steps carefully:
    1 -
    CODESYSControl.cfg
    [SysProcess]
    Command=AllowAll
    [SysFile]
    Windows.WorkingDirectory=C:\ProgramData\CODESYS\CODESYSControlWinV3x64\801BFF8C

    2 - Create a Py file
    3- call Py file in batch file and test the bat.file to be sure if it works fine.
    4- Create a POU file in codesys

    Command : STRING(200):='C:\Users\tsw08\Desktop\Bat.bat';

    IF fbTimer1.Q THEN
    //Reset it and flash again
    counter2 := counter2 +1;
    fbTimer1(IN:= FALSE);
    Test_2 := SysProcessExecuteCommand(pszComand:= Command , pResult:= ADR(dutResult));
    END_IF

    This is my bat.file

    code@echo off
    
    cd "C:\Users\tsw08\Desktop\"
    
    python hello.py
    
    timeout 5
    

    and this is my Python script :

    codimport datetime
    print('Hello,CodeSys')
    d=datetime.datetime.now()
    
    path='log.txt'
    
    f=open(path,"a")
    f.write(str(d)+'\n')
    f.close()e
    
     

Log in to post a comment.