How to handle stdout and stderr on PSP?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
carvalhotk
Posts: 4
Joined: Thu Oct 22, 2009 11:29 pm

How to handle stdout and stderr on PSP?

Post by carvalhotk »

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: Select all

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: Select all

i = 0
while i < 100
  puts "Iteration #&#123;i.to_s&#125;"
  i += 1
end
The program runs fine, finalizes fine, but my stdout looks like:

Code: Select all

Iteration 0
Iteration 1
&#91;...&#93;
Iteration 76
Iterat
EOF

Thank you guys.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Are you sure the atexit handler is being called?
willow :--)
Posts: 107
Joined: Sat Jan 13, 2007 11:50 am

Post by willow :--) »

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...
liberty
Posts: 33
Joined: Wed Sep 16, 2009 11:30 am

Re: How to handle stdout and stderr on PSP?

Post by liberty »

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: Select all

FILE *fp_out = NULL;
FILE *fp_err = NULL;

void PSP_quit&#40;&#41;
&#123;
  if &#40;fp_out&#41; &#123;
    fclose&#40;fp_out&#41;;
  &#125;
  if &#40;fp_err&#41; &#123;
    fclose&#40;fp_err&#41;;
  &#125;
  sceKernelExitGame&#40;&#41;;
&#125;

int main&#40;int argc, char **argv&#41;
&#123;
  &#91; setup the exit callback... &#93;

  fp_out = freopen&#40;"stdout", "w", stdout&#41;;
  fp_err = freopen&#40;"stderr", "w", stderr&#41;;

  atexit&#40;PSP_quit&#41;;

  &#91; run my program, use puts on my Ruby scripts, and so ...&#93;

  exit&#40;EXIT_SUCCESS&#41;;
&#125;
It'll not work. Ive tried to run the following ruby script:

Code: Select all

i = 0
while i < 100
  puts "Iteration #&#123;i.to_s&#125;"
  i += 1
end
The program runs fine, finalizes fine, but my stdout looks like:

Code: Select all

Iteration 0
Iteration 1
&#91;...&#93;
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,
carvalhotk
Posts: 4
Joined: Thu Oct 22, 2009 11:29 pm

Post by carvalhotk »

Thank you, guys. This psplink thing is amazing!
Post Reply