[Script] Kill Microsoft Excel

More
1 year 10 months ago - 1 year 10 months ago #24328 by prashant
This is an appreciation post on how powerful AETL is just with the script feature which allows you to run pascal or python script. 

I had a package which kept failing because Microsoft excel will go in a loop and not allow me to write files. Script + ChatGPT to resuce, here's a simple python script which does the same ( I am sure pascal script will be smaller :))

Code:
import etltools, subprocess def main():     try:         # Check if Excel is running         if subprocess.call('tasklist /FI "IMAGENAME eq excel.exe" | find /I /C "excel.exe"', shell=True) == 0:             # Excel is running, attempt to kill it             subprocess.run(['taskkill', '/F', '/IM', 'excel.exe'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)             etltools.SetVariable('excel_status', 'Excel was running and has been terminated.')         else:             # Excel is not running             etltools.SetVariable('excel_status', 'Excel was not running. No action taken.')                  Result.Value = 1  # Success in both cases     except subprocess.CalledProcessError as e:         etltools.SetVariable('excel_status', f"Failed to kill Excel: {str(e)}")         Result.Value = 0  # Failure     except Exception as e:         etltools.SetVariable('excel_status', f"An unexpected error occurred: {str(e)}")         Result.Value = 0  # Failure main()
Last edit: 1 year 10 months ago by prashant.
The following user(s) said Thank You: Peter.Jonson

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #24329 by Peter.Jonson
Thank you for sharing, we have added your script to the list of exaples

www.etl-tools.com/wiki/advanced-etl-proc...tions/script-action/

Please let us now if you have more

Peter Jonson
ETL Developer
The following user(s) said Thank You: prashant

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago - 1 year 10 months ago #24334 by prashant
Thanks to you posting the link , I saw the example script
import etltools
etltools.SetVariable('<Time>',15)
s=etltools.GetVariable('<Name>')
etltools.WriteToLog('Done')
Result.Value = 0

Being a total log n00b , I have few questions  on etltools.WriteToLog? (Also since I cannot do any experiment due to error posted)

Can it write my error messages to it ? 
Where are they stored ? 
How do I access the log of a given script run ?
I assume set variable is so that variable value can be used later on & write log may be equivalent to display command () ? 


 
Last edit: 1 year 10 months ago by prashant.

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #24338 by prashant
Got my answer for a super simple script ! Write to log is awesome and effectivey replacement for 'display' command

 

Output for below script python script

import etltools

def main():
    try:
        for i in range(1, 11):
            etltools.WriteToLog(f"Number: {i}")
        Result.Value = 1  # Indicating success
    except Exception as e:
        etltools.SetVariable('error_message', str(e))
        Result.Value = 0  # Indicating failure

main()
 
The following user(s) said Thank You: admin

Please Log in or Create an account to join the conversation.

Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Read more
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Google
Accept
Decline
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Google Analytics
Accept
Decline
Functional
Tools used to give you more features when navigating on the website, this can include social sharing.
Advertisement
If you accept, the ads on the page will be adapted to your preferences.
Google Ad
Accept
Decline
Save