I would also suggest embedding all of the command line logic into the python script. That way you have access to things like robust logging, exception handling, and a testing framework. Complex ExecuteCommands are really hard to troubleshoot and debug.
Original Message:
Sent: Mon July 11, 2022 08:17 AM
From: DANIEL BERNATCHEZ
Subject: Executecommand TM1py scritpt
Felix:
So you are saying that the BAT works using your ID logged into the server machine but the BAT does not work running under the user associated with the TM1 service (LOCAL ADMIN).
- I agree with Laurent's suggestion on the C: drive. Though it looks like the Python call is fully qualified with <drive>\<path> for all the files referenced.
- Have you tried using a BAT file to capture the environment variables associated with the Local Admin account. My assumption is that the environment variables of your user ID do not match that of the Local Admin and Python cannot launch properly.
- You could also associate the TM1 Server service call with your user ID temporarily to see if that works but that assumes your ID has the proper rights to invoke the TM1 Server etc..
------------------------------
Daniel Bernatchez
Clear Apex LLC
Original Message:
Sent: Mon July 11, 2022 02:14 AM
From: Laurent Henssien
Subject: Executecommand TM1py scritpt
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
Original Message:
Sent: Fri July 08, 2022 06:04 AM
From: Felix Stuyck
Subject: Executecommand TM1py scritpt
Hello,
I want to trigger a python script using the EXECUTECOMMAND function. The python script is triggered by a .bat file.
The issue is that the TM1 process keeps running (not executed).
I've tested the following:
- When directly executed in CMD it works. (See screenshot)
- Executing the bat from TM1 file works if I run a different command. Ex. a command that moves a file, move "C:\Program Files\Python39\Dimensions.xlsx" "C:\Junyper Notebooks\FNV".
- The location of the python.exe file is accessible to the executing user (local admin).
Info:
Command line in bat file: "C:\Program Files\Python39\python.exe" "C:\Junyper Notebooks\FNV\LoadToExcelScript.py"
TM1 line: EXECUTECOMMAND('C:\Junyper Notebooks\FNV\Run script.bat',1);
Anny suggestions?
------------------------------
Felix Stuyck
------------------------------
#PlanningAnalyticswithWatson