| |

VerySource

 Forgot password?
 Register
Search
View: 1127|Reply: 8

How to get the information displayed by the DOS program running and add it to the Memo control?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-7 00:00:01
| Show all posts |Read mode
targetHandle: = GetWinHandle ('ConsoleWindowClass', nil);
SendMessage (targetHandle, WM_GETTEXT, SizeOf (s), Integer (@s));

Now this method can only get the title, but I want the content of the information displayed by DOS.

help me!
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-31 21:30:01
| Show all posts
Kidnap the Windows console, quack ~~
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-1 13:15:01
| Show all posts
SendMessage, postmessage
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-6 12:15:02
| Show all posts
You can dos output to a text file, and then memo refresh the text file.
Such as:
Use the shellexecute of api to execute the dos command dir> c:\aa.txt;
memo1.SaveToFile ('c:\aa.txt')
Just fine
Reply

Use magic Report

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-5-17 10:30:01
| Show all posts
// c ++
bool RunCmd (String cmd, TStringList * stringlist)
{
    TMemoryStream * memstream = new TMemoryStream ();
    PROCESS_INFORMATION proc;
    STARTUPINFO start;
    SECURITY_ATTRIBUTES sa;
    long ret;
    unsigned long lngBytesread;
    HANDLE hReadPipe, hWritePipe;
    char * strBuff = new char [256];
    if (strBuff == NULL)
    {
        return false;
    }
    sa.nLength = sizeof (SECURITY_ATTRIBUTES);
    sa.bInheritHandle = true;
    sa.lpSecurityDescriptor = NULL;
    ret = CreatePipe (&hReadPipe,&hWritePipe,&sa, 0);
    if (ret == 0)
    {
        // Failed to create pipeline
        return false;
    }
    memset (&start, 0x00, sizeof (STARTUPINFO));
    start.cb = sizeof (STARTUPINFO);
    start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    start.hStdOutput = hWritePipe;
    start.hStdError = hWritePipe;
    bool retc = CreateProcess (NULL, cmd.c_str (), NULL, NULL, true, 0, 0, NULL,&start,&proc);
    if (! retc)
    {
        return false;
    }
    CloseHandle (hWritePipe);
    unsigned long len;
    memstream-> Position = 0;
    while (true)
    {
        memset (strBuff, 0x00,256);
        GetFileSize (hReadPipe,&len);
        ret = ReadFile (hReadPipe, strBuff, 256,&lngBytesread, NULL);
        if (ret == 0)
        {
            break;
        }
        else
        {
            memstream-> Write (strBuff, lngBytesread);
        }
    }
    CloseHandle (proc.hProcess);
    CloseHandle (proc.hThread);
    CloseHandle (hReadPipe);
    memstream-> Position = 0;
    delete strBuff;
    stringlist-> LoadFromStream (memstream);
    memstream-> Clear ();
    delete memstream;
    return true;
}
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-19 23:15:01
| Show all posts
Use pipes. . .
Reply

Use magic Report

0

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-5-31 23:30:01
| Show all posts
There are free controls. StdIORedirect
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Japan

 Author| Post time: 2020-6-4 17:30:01
| Show all posts
I tried the pipeline,

After starting with CreateProcess,
si: STARTUPINFO;
pi: PROCESS_INFORMATION;
CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi)

I can't get the result with [pi.dwProcessId], do I all go to the "pipe"?
Reply

Use magic Report

0

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-1 18:00:01
| Show all posts
Pipe method
There are many examples
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list