Home Download Buy Blog Forum Support

Using win32api extensions

Using win32api extensions

Postby Scam on Fri Oct 25, 2013 1:34 pm

I wonder if there is any possibility to add win32api extensions (pywin32) to Sublime Text? My plugin sends text lines via TCP to a localhost server process which then processes the data and then returns the result back to ST3. All this works fine. I would like to check if the server process is running. If not, then my plugin would start the server before sending first lines. For this I need win32api but there really are no information how to extend the Python distribution which comes built-in with ST3. Is there any easy (or hard) way to do this?

I already tried to copy pywin32 directories to Sublime Text's python3.3.zip with no luck. I also tried to copy pywin32 folder to "C:\Users\...\AppData\Roaming\Sublime Text 3\Packages" folder but it did not work either.
Posts: 12
Joined: Fri Oct 25, 2013 1:15 pm

Re: Using win32api extensions

Postby jbjornson on Fri Oct 25, 2013 3:08 pm

Why do you need win32api? Why not just create a windows batch file that starts your server and call that from your plugin?
Posts: 358
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Using win32api extensions

Postby lunixbochs on Sat Oct 26, 2013 8:52 am

My solution for the equivalent on OS X (using PyObjC from inside Sublime) was to inline the Python code required as a multiline string and run it as a subprocess.

It's a tad ugly, but gets the job done: https://github.com/lunixbochs/AppleScri ... escript.py

Here's a standalone example (python.exe needs to be in your path):

Code: Select all
import os
import subprocess

script = '''
import sys
print 'hi'
print sys.stdin.read()

info = None
if os.name == 'nt':
    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE

p = subprocess.Popen(
    ['python', '-c', script], stdin=subprocess.PIPE,
    stdout=subprocess.PIPE, stderr=subprocess.PIPE,
print('process output:', p.communicate('example input'))
Posts: 92
Joined: Fri Oct 08, 2010 10:18 pm

Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests