Chance1

Getting PID of new created process

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

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


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#4 ·  Posted

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.

Share this post


Link to post
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