| |

VerySource

 Forgot password?
 Register
Search
View: 21|Reply: 7

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

Credits

Newbie

Rank: 1

Credits
3

 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

25

Posts

16

Credits

Newbie

Rank: 1

Credits
16

 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

Credits

Newbie

Rank: 1

Credits
2

 China

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

Use magic Report

0

Threads

13

Posts

8

Credits

Newbie

Rank: 1

Credits
8

 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

5

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 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

Credits

Newbie

Rank: 1

Credits
3

 China

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

Use magic Report

0

Threads

5

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 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

Credits

Newbie

Rank: 1

Credits
3

 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

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

Points Rules

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

Quick Reply To Top Return to the list