how can i get parent process pid on windows using IDL [message #90585] |
Thu, 12 March 2015 06:38  |
Dae-Kyu Shin
Messages: 25 Registered: February 2015
|
Junior Member |
|
|
hi
how can i get parent process pid on windows?
for example
in windows cmd
wmic process get processid, parentprocessi
in IDL
spawn, 'wmic process get processid, parentprocessid', result
but this is not working
is there another way??
thanks
|
|
|
Re: how can i get parent process pid on windows using IDL [message #90586 is a reply to message #90585] |
Thu, 12 March 2015 07:11   |
Jim Pendleton
Messages: 165 Registered: November 2011
|
Senior Member |
|
|
On Thursday, March 12, 2015 at 7:38:48 AM UTC-6, Dae-Kyu Shin wrote:
> hi
>
> how can i get parent process pid on windows?
>
> for example
>
> in windows cmd
>
> wmic process get processid, parentprocessi
>
> in IDL
>
> spawn, 'wmic process get processid, parentprocessid', result
>
> but this is not working
>
> is there another way??
>
> thanks
Try this:
PRINT, CALL_EXTERNAL('kernel32.dll', 'GetCurrentProcessId')
Jim P
|
|
|
Re: how can i get parent process pid on windows using IDL [message #90597 is a reply to message #90586] |
Thu, 12 March 2015 19:45   |
Dae-Kyu Shin
Messages: 25 Registered: February 2015
|
Junior Member |
|
|
2015년 3월 12일 목요일 오후 11시 11분 34초 UTC+9, Jim P 님의 말:
> On Thursday, March 12, 2015 at 7:38:48 AM UTC-6, Dae-Kyu Shin wrote:
>> hi
>>
>> how can i get parent process pid on windows?
>>
>> for example
>>
>> in windows cmd
>>
>> wmic process get processid, parentprocessi
>>
>> in IDL
>>
>> spawn, 'wmic process get processid, parentprocessid', result
>>
>> but this is not working
>>
>> is there another way??
>>
>> thanks
>
> Try this:
> PRINT, CALL_EXTERNAL('kernel32.dll', 'GetCurrentProcessId')
>
> Jim P
thanks
i can get pid using kernel32.dll but this is not ppid(parent process id).
is thete another function for ppid in kernel32.dll?
|
|
|
Re: how can i get parent process pid on windows using IDL [message #90598 is a reply to message #90597] |
Thu, 12 March 2015 23:16  |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Thu, 12 Mar 2015 19:45:46 -0700 (PDT), Dae-Kyu Shin wrote:
> 2015? 3? 12? ??? ?? 11? 11? 34? UTC+9, Jim P ?? ?:
>> On Thursday, March 12, 2015 at 7:38:48 AM UTC-6, Dae-Kyu Shin wrote:
>>> hi
>>>
>>> how can i get parent process pid on windows?
>>>
>>> for example
>>>
>>> in windows cmd
>>>
>>> wmic process get processid, parentprocessi
>>>
>>> in IDL
>>>
>>> spawn, 'wmic process get processid, parentprocessid', result
>>>
>>> but this is not working
>>>
>>> is there another way??
>>>
>>> thanks
>>
>> Try this:
>> PRINT, CALL_EXTERNAL('kernel32.dll', 'GetCurrentProcessId')
>>
>> Jim P
>
> thanks
> i can get pid using kernel32.dll but this is not ppid(parent process id).
> is thete another function for ppid in kernel32.dll?
The problem seems to be, that the Windows wmic command returns an
unicode string ("wide char"). The IDL spawn command stops reading this
string at the first null byte.
You can try to redirect the result from wmic into a temporary file:
spawn,'wmic process get processid, parentprocessid >result.txt'
Then read the file into a binary array and convert the array into an
ASCII string:
openr,lun,/get_lun,'result.txt'
arr=bytarr((fstat(lun)).size)
readu,lun,arr
free_lun,lun
arr=arr[2:*] ; skip the BOM
arr=arr[0:*:2] ; assume all unicode chars to be ASCII
pos=where(arr eq 13b and arr[1:*] eq 10b) ; positions of CRLF
start=[0,pos[0:-2]+2] ; start positions of lines
len=pos-start ; lengths of lines
str=strmid(arr,start,len)
print,str
Is this what you need?
Cheers, Heinz
|
|
|