d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Python And Pathing To Process
12Next
Add Reply New Topic New Poll
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Jul 23 2016 11:12am
Help with using actually path

Code
process = subprocess.Popen(r'"G:\Random\DON'T EVER DELETE\stuff\grow\test.exe"', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)


but since "don't" has a ' it kinda of messes it up any correction?
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jul 23 2016 12:42pm
Run a substitution replacing bad chars with their escapable versions. ' would become \'.

Or just stop using retarded directory names.
Member
Posts: 62,215
Joined: Jun 3 2007
Gold: 9,039.20
Jul 23 2016 01:54pm
Does your path have spaces in it or is that just an example?
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Jul 23 2016 01:55pm
Quote (j0ltk0la @ Jul 23 2016 03:54pm)
Does your path have spaces in it or is that just an example?


thats the literally path

has spaces and the '
Member
Posts: 3,939
Joined: Feb 1 2013
Gold: 2,749.09
Warn: 20%
Jul 23 2016 03:09pm
plenty of things you can do

Code

"\"G:\\Random\\DON'T EVER DELETE\\stuff\\grow\\test.exe\""

'"G:\\Random\\DON\'T EVER DELETE\\stuff\\grow\\test.exe"'

'''"G:\Random\DON'T EVER DELETE\stuff\grow\test.exe"'''

etc

https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
https://docs.python.org/3/reference/lexical_analysis.html#strings

This post was edited by boxboxbox on Jul 23 2016 03:10pm
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Jul 23 2016 03:13pm
something wrong here??

Code
from ctypes import *
import win32con
import win32gui
import win32process
import subprocess
import time
from pathlib import Path


def get_hwnds_for_pid(pid):
def callback(hwnd, hwnds):
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
if found_pid == pid:
print hwnd, "=>", win32gui.GetWindowText(hwnd)
hwnds.append(hwnd)
return True

hwnds = []
win32gui.EnumWindows(callback, hwnds)
return hwnds


class CopyDataStruct(Structure):
_fields_ = [('dwData', c_int),
('cbData', c_int),
('lpData', c_void_p)]


def SendASCommand(cmd):
s = create_string_buffer(cmd)
cds = CopyDataStruct(len(s), len(s), cast(s, c_void_p))
for hwnd in get_hwnds_for_pid(process.pid):
win32gui.SendMessage(hwnd, win32con.WM_COPYDATA, 0, addressof(cds))



if __name__ == '__main__':

process = subprocess.Popen(r'''"G:\Random\DON\'T EVER DELETE\stuff\grow\test.exe"''', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

time.sleep(2.0)

SendASCommand("test")
Member
Posts: 3,939
Joined: Feb 1 2013
Gold: 2,749.09
Warn: 20%
Jul 23 2016 03:22pm
i'll take a look, first thing that jumps out at me is you're using a hodge podge of hammonds libs + ctypes

personally I would ditch hammonds stuff and just use ctypes

also would help if you explain what you're trying to achieve
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Jul 23 2016 03:23pm
Quote (boxboxbox @ Jul 23 2016 05:22pm)
i'll take a look, first thing that jumps out at me is you're using a hodge podge of hammonds libs + ctypes

personally I would ditch hammonds stuff and just use ctypes

also would help if you explain what you're trying to achieve


trying to use python to send copydata
Member
Posts: 3,939
Joined: Feb 1 2013
Gold: 2,749.09
Warn: 20%
Jul 23 2016 03:32pm
this is what your code appears to be trying to do:

1) launch an instance of test.exe (apparently an application which creates one or more windows, it's a mystery based on what you've posted)

2) wait 2 seconds

3) find all windows created by test.exe

4) send a WM_COPYDATA message to each window


this doesn't make a whole lot of sense, so I need to know more about test.exe and what you are ultimately trying to achieve

Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Jul 23 2016 03:33pm
Quote (boxboxbox @ Jul 23 2016 05:32pm)
this is what your code appears to be trying to do:

1) launch an instance of test.exe (apparently an application which creates one or more windows, it's a mystery based on what you've posted)

2) wait 2 seconds

3) find all windows created by test.exe

4) send a WM_COPYDATA message to each window


this doesn't make a whole lot of sense, so I need to know more about test.exe and what you are ultimately trying to achieve


oo i did this at like 3am last night, just googling code, very new to python x.x

so test.exe will already be running, and it will be sending a json strinify obj to it with copydata.

This post was edited by CyberGod on Jul 23 2016 03:35pm
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll