Sublime Forum

Using win32api extensions

#1

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.

0 Likes

#2

Why do you need win32api? Why not just create a windows batch file that starts your server and call that from your plugin?

0 Likes

#3

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: github.com/lunixbochs/AppleScri … escript.py

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

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,
    startupinfo=info,
)
print('process output:', p.communicate('example input'))
0 Likes