Creating a process and gaining access to STDIN, STDOUT and STDERR

  • Hallo,


    we are running an Armstonea9r2 with WinCE and facing a task we need help for.


    We would like to create a process of a shell-like application which takes it command via STDIN and prints out the results via STDOUT.

    To interact with that application the "parent process" needs to access the STDIN and STDOUT of the specific child process.


    There are multiple approaches around the internet, but none of them seems to work on WinCE, for example:

    • Here is a way to pass pipes in the CreateProcess function, but we cannot do that as makros are missing and the documentations states its desktop only.
    • Here the setting of the stdio via pipes is used. But there dont seem to be pipes on WinCE.

    Interestingly, the Pocket CMD v 8.00 seems to allow those operations, as pipes and redirections can be used there.


    I hope there is a simple answer to that problem I overlooked for now.

  • Hello,


    i wonder if it is not sufficient to create the process and just wait for it. STDIN, STDOUT should be still your "console"?

    Pseudo code:

    CreateProcess(_T("ndcucfg"), ... , nonewconsole, ... , processinfo, ...):

    ...

    WaitForSingeObject(processinfo.process, oo);

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello and thank you for the reply!


    The question is then how to write into the "console", because we would like to access STDIN of the child process from the parent process.


    Also while that is in the particular case an option, a more general approach would be preferable.

  • Hello,


    maybe I missunderstood. "We would like to create a process of a shell-like application which takes it command via STDIN and prints out the results via STDOUT" this is your "console".

    Think this is the way "Pocket CMD v 8.00 " calls "cild processes". See below this works. Or what is your parent proccess?


    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,


    I think I can see where the misunderstanding comes from. I'm comming from a Linux environment, where it is possible to just open a pipe and connect it to the STDIN and STDOUT of the newly created process. That way the process starting the new one can send and receive data from it.


    In the example posted, I would like to add something ( I can't be more specific due to missing knowledge :smile: ) inside the wmain function, which receives the output of ndcucfg.exe so I can work with that. Further it would be great to even send commands from wmain function to the running nducfg and then read the output.

  • Just some ideas...


    Shouldn't it be simply possible to access the stdin, stdout and stderr FILE stream handles in the child process? Where is the problem there?


    The bigger problem is the parent process. Maybe here the function freopen() can be useful to re-assign stdin to a file before creating the child process. By writing to the file you might be able to send commands to your child process. I didn't test this, though...


    https://learn.microsoft.com/en…edded/ms861288(v=msdn.10)


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

    Edited 2 times, last by fs-support_HK: Fix link ().

  • Thanks for the reply.


    Unfortunatly we don't have access to change the other process.


    Currently we are starting the process in da cmd environment which can handle the redirection.


    I only wonder how cmd does it...


    As far as I understood the concept, STDIN and STDOUT are always linked to a certain driver (e.g. telnet does it).

    But cmd can redirect things to files. You see, I haven't grabed the whole idea how WEC does it, yet.


    Also the link you send seems to be brocken and incomplete.

  • Hello again,


    >>I only wonder how cmd does it..

    << cmd does it in the way I decribed above (Apr 6th 2023). As far as I see it from souce code (private\winceos\cmd2\...)


    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • As far as I understood, in the code above the STDIN / STDOUT of the parent is used.


    What about writing to files? The cmd process must somehow be able to redirect it to a file when calling:

    />echo "Hallo Welt" >> /exampleOutput.txt


    and also a redirection to input should be managed when

    />echo "I will be send over STDIN" | someProcess.exe

    is called.


    At this point also a huge thank you that you really try to give me an understanding about that. :thumbup:

  • I have fixed the link above.


    Just to be sure that I understand you correctly. You are trying to write the parent process, but the child process is given and cannot be changed. I believe what you want isn't possible, even in Linux.


    You can either create a pipe. Then stdout of one program is used as stdin of the piped program. But then stdout of the second program can not be accessed from the first program. Or you can create a sub-process, but then the child inherits stdin and stdout from the parent, so they both access the same streams.


    In the latter case you can redirect stdin and stdout of the child process to regular files, which may exactly be done by the freopen() function that I talked earlier from, or with SetStdioPathW() when directly accessing the file handles (not the FILE pointer).


    https://learn.microsoft.com/en…n.10)?redirectedfrom=MSDN


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,


    >> />echo "Hallo Welt" >> /exampleOutput.txt

    << In cmd it seems to be solved straightforward they just use _tfopen and write/append the string here.


    >> />echo "I will be send over STDIN" | someProcess.exe

    << In cmd it seems to be a bit more complex (much code anyway). But they use SetStdioPathW as fs-support_HK already told. They create a file "cmdpipe.xxx" with the string and set the file as STDIN by SetStdioPathW (instead of TEL1: or CON1:). Then they create (and open(?)) the process as outlined above.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Ok, I tried it now and it works. Thank you very much.

    I'm going to add some code snipets if anyone else will have the Problem someday.


    First create a file and add some commands to it:

    And then simply start the "shell like" process:

    Code
    1. STARTUPINFO
    2. startInfo;
    3. PROCESS_INFORMATION
    4. processInfo;
    5. int createRet = CreateProcessW( L"<shell like process>", NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &startInfo, &processInfo);

    Thanks again.

  • Hello,

    very nice that it works now.

    And thank you very much too for your feed back and code snipets.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.