New Question
0

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

asked 2018-03-01 20:59:13 +0300

mfontes-ciandt gravatar image

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 :( )

Thanks in advance!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-03-01 22:57:12 +0300

alexpilotti gravatar image

updated 2018-03-01 23:01:43 +0300

Hi,

Could you please run a couple of checks to help troubleshooting this:

  1. Can you replace ./tz-convert.py with the full path (usingthe Windows path separator and quotes if needed)?
  2. Can you check the current path with: python.exe -c “import os; print(os.getpwd())”

Thanks

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-03-01 20:59:13 +0300

Seen: 15 times

Last updated: Mar 01