English 中文(简体)
Grab Programsole Output
原标题:Grab Program s Console Output

我正在为Im公司制定网络管理方案,该公司目前正在与(无关的Ippose公司)进行一些合同工作。

As part of the program, I would like to have a console/telnet(type) clone. I have a working directory system, where I can essentially read all files in directories, and change directories. I also have an easy FTP protocol set up. However I would like to arbitrarily speak to different programs with the standard input/output procedures programmatically. I m not opposed to DLL injection techniques, and other methods, as this is a benign program. If possible it would be awesome if I could just directly use the console easily. (system() would possibly work, however this doesn t allow continued communication or reading back of output)

I m thinking so far of grabbing the PATH environment vars and utilizing that for std commands (ipconfig, netstat, etc) My networking library makes communication easy, but I m just not sure how to interface with the program s console...

<>strong>TL;DR:

是否有预先界定的方案之间标准联系方式?

最佳回答
问题回答

Alright I ve learned a TON about this in the last little while. And here s some information that some people may find useful =]

Code To Create Process With Pipes/File Descriptors as Stdin/out/err:

    STARTUPINFO startInfo;

    PROCESS_INFORMATION procInfo;

    memset((void*) &startInfo, 0, sizeof (startInfo));
    memset((void*) &procInfo,  0, sizeof (procInfo));

    startInfo.cb = sizeof (startInfo);
    startInfo.dwFlags = (STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);

    startInfo.wShowWindow = SW_HIDE; //No Console Window, Thanks.

    startInfo.hStdInput   = (HANDLE)inHandle;
    startInfo.hStdOutput  = (HANDLE)outHandle;
    startInfo.hStdError   = (HANDLE)errHandle;

    char* pe = "cmd"; 
    //This is the program to execute (eg: c:\Windows\System32\cmd.exe)

    CreateProcess(NULL,pe,NULL,NULL,TRUE,0,NULL,NULL,&startInfo,&procInfo);

    return procInfo.hProcess;

Now this is all fine and dandy, but there s an additional little tidbit of information that has really helped me out here. You can use file descriptors for your handles (in/out/err) so you can use straight sockets, with no modification, and you will have direct access to the input and output of the process.

因此,我目前制造隐蔽 con的方法是把两卷单连接到当地,然后将一卷袖珍作为投入和营地; st。 产出和工程; 听觉儿童方案校外员。 它迅速而容易。

如果你不了解如何将一些袖珍连接在一起,那么仅看beej s Guide





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签