Thread: Redirect stdout

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    14

    Redirect stdout

    Hi, i am trying to redirect stdout, in a previous fourum i asked how to redirect ir to a file, and it works, but the thing its that i need to omit that file and save the stdout in a variable, so this variable can be accessed like a queue in c# this is my code, i am using JNI to run JBoss aplication server:

    Code:
    int main(int argc, char **argv) {
    	FILE *stream;
    	char linea[1024];
    	JNIEnv* env;
    	char acumulador[BUFSIZ];	
    	
    	stream = freopen("Hola.txt", "w", stdout);
    	
    	env = create_vm();	
    	invoke_class( env );	
    	
    getchar();
    
    }
    I use this code and works prefectly but like I said i need to omit the hola.txt, i was thinking in some thing like

    Code:
    stream = freopen(acumulador, "w", stdout);
    but it does not work

    there its another C function named:
    Code:
    void setbuf(FILE *stream, char *acumulador);
    but i dont know how to use it

    can some one help me...

    thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Which OS are you running on?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    14
    I am running windows xp, and using visual studio 2005 as a editor

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    14
    Is it possible??
    because I still can´t find a way

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The ms way of redirecting stdout: Creating a Child Process with Redirected Input and Output may be of some interest.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    The nearest thing I can think of is popen()
    http://msdn.microsoft.com/library/de...c_._wpopen.asp

    But all that does it trade a temporary file with having two processes.

    Basically, you put
    Code:
    	env = create_vm();	
    	invoke_class( env );
    inside it's own little executable file, then run that executable file using popen("MyJNI.exe","r") to open a handle to it's stdout.
    You can then read the stdout of that program like you would read a regular file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    14
    thanks a lot i am going to take a look.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Redirect stdout using dup
    By spank in forum Linux Programming
    Replies: 13
    Last Post: 04-03-2008, 05:16 PM
  2. redirect stdout to editbox
    By kerm1t in forum Windows Programming
    Replies: 1
    Last Post: 05-11-2005, 10:32 PM
  3. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  4. Who to redirect stdout to a file in C
    By edugarcia in forum Linux Programming
    Replies: 3
    Last Post: 10-01-2004, 12:18 AM
  5. redirect stdout to a file?
    By Brian in forum C Programming
    Replies: 5
    Last Post: 01-15-2002, 01:06 PM