Jump to content

Getting PID of new created process


Recommended Posts

Hey guys, I am tyring to send commands (using controlsend) to a window that is being created by the cmd window. The cmd window gets a command to open up telnet, from there, I am unable to send anything to the telnet(executbale) window. I have working code that uses the PID of the process to send input back to the window which it was prompted for (It works on the cmd window using it's PID). I tired using the window title and WinGetProcess to get the Pid of telnet, but the result is -1. 

$TPid = WinGetProcess("telnet msn-devqa")

 

 Any ideas guys? Thanks in advance.

 

EDIT: I am using control send because the cmd window(and telnet) will prompt the user for something (username or password) and I need to send it back to the cmd window.

Edited by Chance1
Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the DEV forum very clearly states:

Quote

Do not create AutoIt-related topics here, use AutoIt General Help and Support

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

From ControlSend's documentation:

Quote

ControlSend() is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages).

ControlSend won't work for CMD

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

I am using:

StdinWrite($Pid, "...")

to write to cmd, but after the execution of some of the commands, cmd prompts the user to input data. I know when the cmd window will prompt the  user so, for the users response I use the following function:

Func OutputPrompt($input, $ppid)
    $winhandle = 0
    $WindowList = WinList()
    For $i = 1 to $WindowList[0][0] ;loop to find the handle of the cmd window for the PID
        If WinGetProcess($WindowList[$i][1])= $ppid Then
            $winhandle=$WindowList[$i][1]  ;set the handle
        EndIf
    Next ;loop on for loop

    If $winhandle = 0 Then ;handle wasn't found --exit script
        MsgBox(0, "EXIT", "CRITICAL ERROR: HANDLE NOT FOUND - Terminating Script", 2000)
        Call("SuperTerminate")
        Exit
    EndIf
    ;output token to cmd window
    ControlSend($winhandle, "", '', $input  & "{ENTER}")
    sleep(2000)

EndFunc

which I know works everytime.

So, as you can see in the function above, I use the pid of the window to which I am writting to too properly answer the prompted questions. The issue is, one of the commands issued in my script crates a new window and I am unable to get the pid of that new window. Because I cannot get the pid of the new window correctly, I am unable to output to it at all.

Does anyone have an idea of how to get the pid of the new window created? As stated earlier, I know what the title of the new window will be, but WinGetProcess returns -1 for the pid. Thanks in advance.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...