Windows alternative to pexpect

前端 未结 3 449
灰色年华
灰色年华 2021-01-04 22:50

I\'m trying to write a cross-platform tool that runs specific commands, expects certain output for verification, and sends certain output (like username/password) f

相关标签:
3条回答
  • 2021-01-04 23:40

    You can use wexpect ("Windows alternative of pexpect", Python Software Foundation). It has the same functions, and it works on Windows .

    0 讨论(0)
  • 2021-01-04 23:49

    Instead of using pexpect.spawn you can use pexpect.popen_spawn.PopenSpawn for windows.

    child = pexpect.popen_spawn.PopenSpawn('cmd', timeout=1)
    child.send('ipconfig')
    child.expect('Wireless', timeout=None)
    
    0 讨论(0)
  • 2021-01-04 23:56

    Better solution is to move DOCKER. It will solve the entire Linux <-> Windows Dependecies in all kind of process. Very simple steps are there to convert a any .py code into a Docker-image. This will be the Futreistic an doptimised solution to use pexpect in windows.

    The Example for Encapsulating Python in container: In Linux : Step 1: https://docs.docker.com/engine/install/centos/ After the installation ,one can get docker as a sytem command in linux. Step 2 : Create a directory , and copy the python in that directory and create a ne file called "Dockerfile" and also have the requirements.txt

    root@host_name~#cd Demo_docker Demo_code.py DOckerfile requirements.txt

    vi Demo_code.py
    import pexpect
    a=2+2
    print(a)

    vi requirements.txt pexpect==4.8.0

    vi Dockerfile python:latest COPY . . COPY . reqitrements.txt RUN pip3 install -- requirement requirements.txt CMD ["python","Demo.py"]

    Step 3: Use Docker build command to build and run and you can upload this to "dockerHUB" and then pull to any where in the world.

    After you pushed the image to Docker-Hub , in windows one need to download "Docker Desktop Appliaction" and the use "Docker pull command to pull the repo which you pushed to Docker-hub

    0 讨论(0)
提交回复
热议问题