forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to handle stdout and stderr on PSP?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
carvalhotk



Joined: 22 Oct 2009
Posts: 4

PostPosted: Mon Oct 26, 2009 1:37 am    Post subject: How to handle stdout and stderr on PSP? Reply with quote

Hello, there.

The question is that: how is the right way to handle stdout and stderr on the PSP? I mean, I can't just use pspDebugScreenPrintf, because the libraries that are extern to my program don't use it. So, I fell like I have to redirect the output to files, but as I have seen, it's not a good way to do it.

For example, if I use the following code:

Code:
FILE *fp_out = NULL;
FILE *fp_err = NULL;

void PSP_quit()
{
  if (fp_out) {
    fclose(fp_out);
  }
  if (fp_err) {
    fclose(fp_err);
  }
  sceKernelExitGame();
}

int main(int argc, char **argv)
{
  [ setup the exit callback... ]

  fp_out = freopen("stdout", "w", stdout);
  fp_err = freopen("stderr", "w", stderr);

  atexit(PSP_quit);

  [ run my program, use puts on my Ruby scripts, and so ...]

  exit(EXIT_SUCCESS);
}


It'll not work. Ive tried to run the following ruby script:

Code:
i = 0
while i < 100
  puts "Iteration #{i.to_s}"
  i += 1
end


The program runs fine, finalizes fine, but my stdout looks like:

Code:
Iteration 0
Iteration 1
[...]
Iteration 76
Iterat
EOF



Thank you guys.
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Oct 26, 2009 2:43 am    Post subject: Reply with quote

Are you sure the atexit handler is being called?
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Mon Oct 26, 2009 12:18 pm    Post subject: Reply with quote

stderr works correctly if you test your application through PSPLink, no Voodoo magic is required, so I'm not entirely sure what you're trying to accomplish...
_________________
Wagic. Play that card game against an AI on your PSP
Back to top
View user's profile Send private message
liberty



Joined: 16 Sep 2009
Posts: 35

PostPosted: Thu Oct 29, 2009 6:14 am    Post subject: Re: How to handle stdout and stderr on PSP? Reply with quote

carvalhotk wrote:
Hello, there.

The question is that: how is the right way to handle stdout and stderr on the PSP? I mean, I can't just use pspDebugScreenPrintf, because the libraries that are extern to my program don't use it. So, I fell like I have to redirect the output to files, but as I have seen, it's not a good way to do it.

For example, if I use the following code:

Code:
FILE *fp_out = NULL;
FILE *fp_err = NULL;

void PSP_quit()
{
  if (fp_out) {
    fclose(fp_out);
  }
  if (fp_err) {
    fclose(fp_err);
  }
  sceKernelExitGame();
}

int main(int argc, char **argv)
{
  [ setup the exit callback... ]

  fp_out = freopen("stdout", "w", stdout);
  fp_err = freopen("stderr", "w", stderr);

  atexit(PSP_quit);

  [ run my program, use puts on my Ruby scripts, and so ...]

  exit(EXIT_SUCCESS);
}


It'll not work. Ive tried to run the following ruby script:

Code:
i = 0
while i < 100
  puts "Iteration #{i.to_s}"
  i += 1
end


The program runs fine, finalizes fine, but my stdout looks like:

Code:
Iteration 0
Iteration 1
[...]
Iteration 76
Iterat
EOF



Thank you guys.


You can just include stdio.h and do not redefine printf then you can use standard C library and get output from PSPLink,
Back to top
View user's profile Send private message
carvalhotk



Joined: 22 Oct 2009
Posts: 4

PostPosted: Tue Nov 03, 2009 3:41 am    Post subject: Reply with quote

Thank you, guys. This psplink thing is amazing!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group