Simulate user input in Jenkins Python script
This requirement is rare, but it is difficult to test successfully, so we need to record it.
We use Jenkins + TexturePacker to automatically package and convert resources.
To run TexturePacker for the first time, enter agree in the command line to confirm the copyright. The Jenkins system environment is independent from the desktop system, so you have to enter agree again in Jenkins. So there is a very disgusting situation. The command line running TexturePacker in Jenkins does not input agree to the user.
Fortunately, there are omnipotent python scripts. It can simulate user input. In this way, you only need to Execute this script in Jenkins (create a Job and run the following script in Execute Shell)
#! Python.exe import subprocesshils = subprocess. popen ([r 'd: \ Workspace \ TexturePacker \ bin \ TexturePacker.exe '], stdin = subprocess. PIPE, stdout = subprocess. PIPE) result = Hils. communicate (input = r 'agree ') [0] print Hils. returncodeprint Hils. communicate ()