Sponsored Content
Top Forums Programming how to redirect back to stdout Post 302288484 by Corona688 on Tuesday 17th of February 2009 10:40:58 AM
Old 02-17-2009
Doing this in C++ is the same as doing this in C since the system calls are all the same.

stdin is probably the same terminal, but since it's opened with the wrong file mode duplicating it won't work right. But you might be able to figure out what the terminal at least is:
Code:
$ ls -l /dev/fd/0
lrwx------ 1 monttyle monttyle 64 Feb 17 09:15 /dev/fd/0 -> /dev/pts/1
$

If you don't have that, try /dev/stdin or /proc/self/fd/0

You can retrieve the same info in your C/C++ program with the readlink() call, then open the terminal and re-duplicate it over stdout and stderr.

This, of course, won't work when stdin was never a terminal, so be careful to not let your program do crazy things when you pipe or redirect into it.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect stdout and stderr

How can I redirect and append stdout and stderr to a file when using cron? Here is my crontab file: */5 * * * * /dir/php /dir/process_fns.php >>& /dir/dump.txt Cron gives me an 'unexpected character found in line' when trying to add my crontab file. Regards, Zach Curtis POPULUS (8 Replies)
Discussion started by: zcurtis
8 Replies

2. UNIX for Advanced & Expert Users

problem with redirect stdout to file

Hi all hope you can help as I am going MAD!!! :eek: The below is in a shell script but the redirection in the sed line does not work and outputs to the screen and the $fname_2 does note get created ????? Can any one help ?? #!/bin/ksh cd /app/ for fname in `ls -1 X*` do sed 1d $fname... (3 Replies)
Discussion started by: mlucas
3 Replies

3. UNIX for Dummies Questions & Answers

stdout back to tty

Hi everyone! Well, this is the thing.. I sent a process's stdout to /dev/null. This process is very time consuming and after a week it keeps running, what I need is to switch the stdout back to screen to see what's going on. Anyone know if it's possible and how to do it? Thanks and... (3 Replies)
Discussion started by: piltrafa
3 Replies

4. UNIX for Advanced & Expert Users

STDOUT redirect to a FILE, when fuser command is used !!

Hi all, I have the following script: ------------------------------------------------- #SCRIPT TO CHECK WHO HAS ACCESSED THE LOG/FILE IN PAST 'N' MINUTES, AND MAIL ACCORDINGLY. MYPATH="/clocal/mqbrkrs/user/mqsiadm/sanjay/" MAIL_RECIPIENTS="vg517@dcx.com" Subject="File accessed in last... (6 Replies)
Discussion started by: varungupta
6 Replies

5. Shell Programming and Scripting

How to redirect stderr and stdout to a file

Hi friends I am facing one problem while redirecting the out of the stderr and stdout to a file let example my problem with a simple example I have a file (say test.sh)in which i run 2 command in the background ps -ef & ls & and now i am run this file and redirect the output to a file... (8 Replies)
Discussion started by: sushantnirwan
8 Replies

6. UNIX for Dummies Questions & Answers

How to put the STDOUT back to terminal

I have put the file descriptor 1 to file, using command exec 1>>out.txt Then I could not see any output on the screen, how could I restore the default output to terminal? :mad: Thanks (3 Replies)
Discussion started by: biglau
3 Replies

7. Programming

redirect stdout

hello again! i use dup2 to redirect stdout. I run what i want, now i want undo this redirection. how can i do that? thanx in advance (7 Replies)
Discussion started by: nicos
7 Replies

8. Shell Programming and Scripting

redirect STDOUT to a file in a subshell

Hi, I would like to avoid re-directing line by line to a file. What is the best way to re-direct STDOUT to a file in a subshell? Thanks in advance. Cheers Vj (1 Reply)
Discussion started by: tnvee
1 Replies

9. Red Hat

Redirect STDOUT and STDERR of chsh

EDIT: Nevermind, figured it out! Forgot to put backslashes in my perl script to not process literals! Hi everyone. I am trying to have this command pass silently. (no output) chsh -s /bin/sh news Currently it outputs. I've tried.... &> /dev/null 1> /dev/null 2>&1 /dev/null 1>&2... (1 Reply)
Discussion started by: austinharris43
1 Replies

10. Shell Programming and Scripting

Bizzare behavior on redirect of stdout

Oracle Linux 5.6 64-bit (derivative of RHEL) Dear Ann Landers, This is about as bizarre as anything I've ever seen. I have a little test script I've been working with. When I redirect stdout to a file, no file. Make a copy of the script to another name. Execute it and redirect stdout, and... (4 Replies)
Discussion started by: edstevens
4 Replies
OBEX_TEST(1)							   User commands						      OBEX_TEST(1)

NAME
obex_test - interactive test application for the openobex library SYNOPSIS
obex_test [[-s port] | [-r port] | [-i] | [-b [address] [channel]] | [-u interface]] DESCRIPTION
obex_test is a test application for the openobex library. It uses an interactive mode but the access method is selcted with command line arguments. This program is designed to be an example application for the openobex library. OPTIONS
-s This is the default. It selects cable obex. The port argument is optional (default: /dev/ttyS0) -r Select cable obex for the Ericsson R320 mobile phone. The port argument is optional (default: /dev/ttyS0) -i Select obex over IrDA. -b Select obex over bluetooth. Both, address and channel are actually optional. Default channel is 4, default address is ANY. -u Select usb obex (CDC). If the interface argument is omitted, a list of available interface is written to stdout. INTERACTIVE MODE
: COMMANDS c connect to the remote side (client mode) d disconnect from the remote side g issue a GET request p issue a PUT request q quit the program s go into server mode t change the path on the remote side x issue a PUSH request AUTHOR
Hendrik Sattler <post@hendrik-sattler.de> initial version of manpage openobex 1.4 2008-11-23 OBEX_TEST(1)
All times are GMT -4. The time now is 10:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy