[SOLVED] run(powershell script.ps1) timeout

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
swbsf
Messages: 8
Registration: July 27, 2017 - 09:50

July 27, 2017 - 10:05

Good morning,
I'm trying my luck here.
I'm creating a post-installation package that will configure the workstations by running a PowerShell script. So, to answer a potential question of "why am I not doing this post-installation in pure Python?" right away: because I already have the PowerShell script, and it's very long. Besides, there's no reason why we can't run PowerShell!
So whatever the script, it times out; it seems that psutils.Popen is not detecting the script's exit code.
For this example, I tested it with a very simple script:

Code: Select all

echo "coucou" > c:\tmp\fichier.txt
exit
Then in Python:

Code: Select all

run('powershell -NoProfile -NonInteractive -File c:/tmp/test.ps1')
I observe that the code is executed correctly, but the instruction never finishes, or rather at timeout=600.
Any ideas? What other solutions are there? I also tried it with the same error:

Code: Select all

with open('test.ps1','r') as f:
   data=f.read()
run_powershell(data)
And it's even more bizarre.
Thank you in advance!
Last edited by swbsf on August 1, 2017 - 09:28, edited 1 time.
swbsf
Messages: 8
Registration: July 27, 2017 - 09:50

July 27, 2017 - 11:44

For your information, the problem is circumvented with a:

Code: Select all

import subprocess
cmd="powershell -NoProfile -NonInteractive -File c:\\tmp\\test.ps1"
proc = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
proc.wait()
stdo,stde = proc.communicate()
print(stdo,stde)
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

July 27, 2017 - 11:49

Do you have PowerShell version 3 installed on this machine?

https://lists.tranquil.it/pipermail/wap ... 02340.html
swbsf
Messages: 8
Registration: July 27, 2017 - 09:50

July 31, 2017 - 09:01

It's Windows 10, so yes.

Code: Select all

    PS C:\Windows\system32> $PSVersionTable.PSversion
     
    Major  Minor  Build  Revision
    -----  -----  -----  --------
    5      0      10586  122
swbsf
Messages: 8
Registration: July 27, 2017 - 09:50

August 1, 2017 - 09:27

Okay, I'm taking back what I said. The error was indeed related to the PowerShell version being less than 3.0. On one hand, it was PS 2.0, and on the other, just a slow machine, so the timeout of 3 was too short to run a simple PS command.
Thank you for your detailed help :)
Locked