Hello Felix,
Just a couple questions to put aside the obvious as I see you do a "cd C:\something" :
- is your tm1 data directory on C: drive ?
- when you run the batch file from the command line, do you run it from your tm1 data directory ?
If it is on another drive you'll need to add a "C:" command before the "cd" in your batch file, cd does not change drive...
For the timestamp I would simply do a TIMST in TM1 then build the the batch file with AsciiOutput commands, I don't like standalone scripts... and I also like simplicity, this dos command is just too complex to handle for anyone that is not fluent in command line code :)
Cheers,
------------------------------
Laurent Henssien
C L A R I T Y
https://www.clarity.consulting------------------------------
Original Message:
Sent: Fri July 08, 2022 12:11 PM
From: George Tonkin
Subject: Executecommand TM1py scritpt
HI Felix,
That Break concerns me a bit and wondering if it somehow may be executing and exiting the batch file before running the python script.
Should not do so if running from cmd works but one never knows without stepping through the code.
To try and skip the loops etc. could you try something like:
set myTimeTemp=%time: =0%set myTime=%date:~0,4%%date:~5,2%%date:~8,2%-%myTimeTemp:~0,2%%myTimeTemp:~3,2%cd "C:\Junyper Notebooks\FNV\Scripts""C:\Program Files\Python39\python.exe" "C:\Junyper Notebooks\FNV\Scripts\LoadToExcelScript.py" > .\logs\log_%myTime%.log 2>>errors.err
------------------------------
George Tonkin
------------------------------
Original Message:
Sent: Fri July 08, 2022 11:03 AM
From: Felix Stuyck
Subject: Executecommand TM1py scritpt
I've tried your suggestion and witnessed the following behaviour.
The bat code is updated to:
cd C:\Junyper Notebooks\FNV\Scripts
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I break>errors.err
"C:\Program Files\Python39\python.exe" "C:\Junyper Notebooks\FNV\Scripts\LoadToExcelScript.py" > .\logs\log_%datetime:~0,8%-%datetime:~8,6%.log 2>> errors.err
When run from CMD this generates a log file with the output of the CMD (screenshot).
When run from TM1 this generates and empty log file. To me, this means that the .py file is still not triggerd.
The TM1 process does return success, but this is not true. It is probably because the first line in the bat file was executed successfully.
------------------------------
Felix Stuyck
Original Message:
Sent: Fri July 08, 2022 09:08 AM
From: George Tonkin
Subject: Executecommand TM1py scritpt
May be worthwhile adding some more code to the batch file to echo your environment to a text file and possibly use 2>error.txt on the command executing the python script to see if there is an error being generated.
------------------------------
George Tonkin
Original Message:
Sent: Fri July 08, 2022 07:53 AM
From: Felix Stuyck
Subject: Executecommand TM1py scritpt
Hi George,
Thanks for the response.
1) I actualy want the process to wait, so I get an indication when it is finished.
2) I've tested your suggestion, but this does not change anything.
EXECUTECOMMAND('CMD /C "C:\Junyper Notebooks\FNV\Run script.bat"',1);
------------------------------
Felix Stuyck
Original Message:
Sent: Fri July 08, 2022 06:39 AM
From: George Tonkin
Subject: Executecommand TM1py scritpt
HI Felix,
Two things:
1) Your ExecuteCommand has a Wait argument of 1 telling TI to wait until the call has completed. If you want to trigger the python script and let it run in the background, try set the Wait to 0
2) I typically execute batch files using CMD /C <batch> e.g. EXECUTECOMMAND('CMD /C C:\Junyper Notebooks\FNV\Run script.bat',1);
This tells the command prompt to execute and not to wait.
Hope that helps.
------------------------------
George Tonkin