1

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.

ranjjose
  • 2,138
  • 1
  • 24
  • 46
Daniel
  • 295
  • 1
  • 3
  • 5

1 Answers1

2

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.

dlp
  • 430
  • 4
  • 9
  • I tried that but it didn't seem to run the imagegrab.py file. Thanks for the fast reply =) – Daniel Apr 30 '13 at 03:12
  • If any of the folders that imagegrab.py is in have spaces, wrap the file path with quotes, like `python "C:\Path To\The\Python\File\imagegrab.py"`. Also run the batch file on the command line manually to see if any errors come up. Click the start menu, All Programs, Accessories folder, Command Prompt. In the screen that comes up, run the BAT file by calling the path such as `"C:\Path\To\BAT\imagegrab.bat"`. – dlp Apr 30 '13 at 13:54
  • Thanks for that, It was a quote problem, I figured that out a while after replying to you. its all working now, thanks again =) – Daniel Apr 30 '13 at 20:51