Search code examples
pythonbatch-filepymel

My .bat file wont read the lines after using `python`


I need to create a .bat file that a pymel script calls, I currently have this as my bat file:

PATH C:\Python26 
python
from PIL import ImageGrab
import time
time.sleep(5)
ImageGrab.grab().save("screen_capture.jpg", "JPEG")

It stops reading the bat file at python and doesn't go any further.


Solution

  • Never used pymel, however it looks like you put all of your Python code in your BAT file. That won't work. You need to separate them out to two separate files, the BAT file and a Python .py file which contains only Python code. Let's make your .py file look like this:

    # imagegrab.py
    from PIL import ImageGrab
    import time
    time.sleep(5)
    ImageGrab.grab().save("screen_capture.jpg", "JPEG")
    

    And your BAT file like this:

    rem imagegrab.bat
    PATH C:\Python26
    python C:\Path\To\imagegrab.py
    

    Substitute C:\Path\To\ with wherever you save the .py file.