redirecting stdin of a task to file and back - VxWorks

This is a discussion on redirecting stdin of a task to file and back - VxWorks ; Hi, I am having a task that takes input from normal console. Somewhere in the middle, I need to take input from a file. I use ioTaskStdGet/Set to save old stdin and set new stdin to the file fd I ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: redirecting stdin of a task to file and back

  1. redirecting stdin of a task to file and back

    Hi,
    I am having a task that takes input from normal console. Somewhere in
    the middle, I need to take input from a file. I use ioTaskStdGet/Set to
    save old stdin and set new stdin to the file fd I have. Once I am done,
    I use ioTaskSet to set the stdin back to the old one. But I see that
    the stdin is not restored to the old stdin. I have tried using
    ioGlobalStdGet/Set as well. But no help.

    I am able to receive inputs to my task. I had made tShell lower
    priority so my task gets the input. As long as I dont do the stdin
    redirect, I am able to get the input to my task. But once I run this
    code, the stdin gets lost even after restoring it back.

    Any help will be greatly appreciated!

    Thanks!

    Here is the code snippet:

    ........
    ........
    printf("Press any key to start the demo...");
    getchar(); <------------------------------ Waits for the key input

    /* now run the step1.sh */
    step1Stdin = open (step1_file, O_RDONLY, 0);
    if(step1Stdin == ERROR) {
    printf("ERROR: Cannot open file %s\n", step1_file);
    return;
    }

    printf("\n\n\rRunning script %s...\n", step1_file);

    /* set stdin to the new file so ag5gShell can execute it */
    oldStdin = ioTaskStdGet (0, STD_IN); /* save original std in */
    ioTaskStdSet (0, STD_IN, step1Stdin); /* set std in to script */

    executeScript(); <----------------------- reads the step1_file from
    stdin and executes it.

    /* now restore the stdin */
    ioTaskStdSet (0, STD_IN, oldStdin);
    close(step1Stdin);

    printf("Completed running script %s.\nPress any key to
    continue...", step1_file);
    getchar(); <------------------- Does not wait for my input
    ......
    ......


  2. Re: redirecting stdin of a task to file and back


    On 29 Nov 2005, vi_jay2k@yahoo.com wrote:
    > Hi, I am having a task that takes input from normal
    > console. Somewhere in the middle, I need to take input from a
    > file. I use ioTaskStdGet/Set to save old stdin and set new stdin to
    > the file fd I have. Once I am done, I use ioTaskSet to set the stdin
    > back to the old one. But I see that the stdin is not restored to the
    > old stdin. I have tried using ioGlobalStdGet/Set as well. But no
    > help.
    >
    > I am able to receive inputs to my task. I had made tShell lower
    > priority so my task gets the input. As long as I dont do the stdin
    > redirect, I am able to get the input to my task. But once I run this
    > code, the stdin gets lost even after restoring it back.



    There is some weirdness when running from a network shell. If you run
    this from a serial console, then everything is probably ok. There are
    some weird names like "tyio/0" [something like that, try iosFdShow and
    @iosFdShow]. The stdin is set to the console, but it is "redirected"
    by the Tornado tools.

    The defaults have 0,1,2 printed in the show commands afair. You have
    to reset the I/O to the windshell. There might be a better way to do
    this. The real target is not suppose to know about the windshell...

    fwiw,
    Bill Pringlemeir.

    --
    It isn't premarital sex if you have no intention of getting married.
    - Matt Barry

    vxWorks FAQ, "http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html"

  3. Re: redirecting stdin of a task to file and back

    I found out the problem. The function executeScript() returns when it
    hits the EOF. Aparrently, the redirection does not work right if the
    stdin is pointing EOF. I did a rewind() making it point to the start
    and the redirect back worked fine.

    Thanks!


  4. Re: redirecting stdin of a task to file and back

    can you please post the solution with the changes>
    Thanks

+ Reply to Thread