problem closing stdout - VxWorks

This is a discussion on problem closing stdout - VxWorks ; Hi EveryOne: I am New to vxworks.I am trying to get the list of files in the directories using ls() and i want to redirect ls() > to a pipe so i am closing the stdout file descriptor and duplicating ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: problem closing stdout

  1. problem closing stdout

    Hi EveryOne:
    I am New to vxworks.I am trying to get the
    list of files in the directories using ls() and i want to redirect
    ls() > to a pipe so i am closing the stdout file descriptor and
    duplicating pipe fileDescriptor.But the pbm im facing is when
    execution comes to line close(1) my simulator gets hanged.

    I m working in workBench 2.5 .

    Can anyone give me some suggestions.


  2. Re: problem closing stdout

    On Aug 14, 5:09 pm, senthil wrote:
    > Hi EveryOne:
    > I am New to vxworks.I am trying to get the
    > list of files in the directories using ls() and i want to redirect
    > ls() > to a pipe so i am closing the stdout file descriptor and
    > duplicating pipe fileDescriptor.But the pbm im facing is when
    > execution comes to line close(1) my simulator gets hanged.
    >
    > I m working in workBench 2.5 .
    >
    > Can anyone give me some suggestions.


    In VxWorks the File descriptors are shared and accessible across
    tasks. So, it is quite possible that the FD stdout that was closed was
    being used by some other task.

    In general, closing the stdin, stdout and stderr is not recommended.

    Now, coming to redirection of the output - there are specific APIs
    that would help you achieve this -

    1) iosTaskStdSet( ) - set the file descriptor for task standard input/
    output/error

    void ioTaskStdSet
    (
    int taskId, /* task whose std fd is to be set (0 = self) */
    int stdFd, /* std input (0), output (1), or error (2) */
    int newFd /* new underlying file descriptor */
    )

    2) ioGlobalStdSet( ) - set the file descriptor for global standard
    input/output/error

    int ioGlobalStdGet
    (
    int stdFd /* std input (0), output (1), or error (2) */
    )

    Hope this would help you!

    Regards,
    Sriram.


  3. Re: problem closing stdout

    Thanx for ur suggestions.
    I tried it now i am able to redirect stdout to pipe.
    is there any way after doing some process (in same Task) can i get
    back the redirected file descriptor to standard output.


  4. Re: problem closing stdout

    On Aug 16, 9:47 am, senthil wrote:
    > Thanx for ur suggestions.


    Well, sorry, I was slightly wrong with the API descriptions earlier.
    Please find them corrected below -

    The two APIs related to redirecting the standard input, output and
    error are as below -

    1) ioTaskStdSet( ) - set the file descriptor for task standard input/
    output/error

    void ioTaskStdSet
    (
    int taskId, /* task whose std fd is to be set (0 = self) */
    int stdFd, /* std input (0), output (1), or error (2) */
    int newFd /* new underlying file descriptor */
    )

    2) ioGlobalStdSet( ) - set the file descriptor for global standard
    input/output/error

    void ioGlobalStdSet
    (
    int stdFd, /* std input (0), output (1), or error (2) */
    int newFd /* new underlying file descriptor */
    )

    > I tried it now i am able to redirect stdout to pipe.


    I assume that you had used the correct form of the API while you were
    able to successfully redirect the stdout to pipe.

    > is there any way after doing some process (in same Task) can i get
    > back the redirected file descriptor to standard output.


    Yes, you can retrieve and store the current file descriptor that
    denotes the stdout before redirection. Once you are done with the
    needed processing, you can set back the stdout to the file descriptor
    that you had stored earlier.

    The current file descriptor that denote the stdout can be obtained by
    using the following APIs -

    1) ioTaskStdGet( ) - get the file descriptor for task standard input/
    output/error

    int ioTaskStdGet
    (
    int taskId, /* ID of desired task (0 = self) */
    int stdFd /* std input (0), output (1), or error (2) */
    )

    2) ioGlobalStdGet( ) - get the file descriptor for global standard
    input/output/error

    int ioGlobalStdGet
    (
    int stdFd /* std input (0), output (1), or error (2) */
    )

    Let us consider an example below -

    int pipeFd = 10;
    int prevStdOut = ioTaskStdGet(0, 1); /* Retrieve and store (backup)
    the current stdout file descriptor */

    if(prevStdOut != ERROR) {
    ioTaskStdSet(0, 1, pipeFd); /* Redirect the stdout to the pipe
    device */

    ....
    .... /* Do some processing */
    ....

    ioTaskStdSet(0, 1, prevStdOut); /* Restore the stdout to what it was
    earlier */
    }


    Hope this answered your query!

    Regards,
    Sriram.



  5. Re: problem closing stdout

    Hai
    Thanx for ur suggestions.
    I tried it now i am able to get back STDOUT back to my task.


+ Reply to Thread