New Question

# Revision history [back]

### Issue calling a '.py' script from 'user_data'

I have the following code on 'user_data', which is being interpreted by Powershell:

$PythonDir = "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python"$ResultMsg = & "$PythonDir\python.exe" ./tz-convert.py$tz


This has been causing a big headache for me and team: there is an unknown error where the .py file cannot be executed. I haven't figured out a why to extract any log or error message. When I run exact code above directly from a Powershell prompt, the execution goes perfectly. And yes, "tz-convert.py" file is available on that same directory, hence "./" notation.

My guess is that trying to run a .py file is the problem, because below modification runs perfectly fine, outputting "Python 3.4.3", so we know "python.exe" path is perfect and Python itself is able to run fine on my env:

$PythonDir = "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python"$ResultMsg = & "$PythonDir\python.exe" -V  To further validate this, I created a "hello.py" file that simply runs: print("Hello world")  And invoking it resulted in the same error, with Python crashing with no output AFAIK: $PythonDir = "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python"
$ResultMsg = & "$PythonDir\python.exe" .\hello.py


Question is: is it possible at all to invoke a .py file (with a function, and a return string and exit codes) from "user_data", to be executed during a Win VM creation?

We are using "tz-convert.py" to convert timezone information, from "America/New_York" format to the "Eastern Standard Time" format.

If it turns out to be impossible using a Python function for this conversion, I'll find a way to do this using pure Powershell (kinda bad :( )