When executing Python via xp_cmdshell, print does not return to the SQL Output

91 views Asked by At

When executing the following in SQL Server 2019, the output returned is NULL:

EXEC xp_cmdshell '<location>\python.exe <location>\HelloWorld.py'

When executing HelloWorld.py in Command Prompt or PowerShell, Hello World! is returned. The HelloWorld.py file contains print("Hello World!").

I tried wrapping the python command in a .bat file:

EXEC xp_cmdshell '<location>\HelloWorld.bat'

The output returned was the following:

NULL
<location>\python.exe <location>\HelloWorld.py
NULL

The expected output, according to this link:

NULL
<location>\python.exe <location>\HelloWorld.py
Hello World!
NULL

How do I get the expected output?

0

There are 0 answers