suppress terminal outputs

Hello,

I am trying to navigate within the file system using C programming. Here I
use system( “cd [folder]” ) e.g. to navigate into a desired folder. When
this folder exists, system() returns “0”; when it doesn’t exist system()
returns e.g. “256” AND prints out an error message like “sh: cd: [folder] -
no such file or directory” on the active terminal window.

How can I suppress this error output on the screen?

Nnamdi

Nnamdi Kohn <nnamdi.kohn@tu-bs.de> wrote:

Hello,

I am trying to navigate within the file system using C programming. Here I
use system( “cd [folder]” ) e.g. to navigate into a desired folder. When
this folder exists, system() returns “0”; when it doesn’t exist system()
returns e.g. “256” AND prints out an error message like “sh: cd: [folder] -
no such file or directory” on the active terminal window.

How can I suppress this error output on the screen?

use chdir() instead of system()…

Or, if you insist on using system(), try redirecting its standard output
and standard error elsewhere…

Cheers,
-RK


[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~museum/

Robert Krten wrote:

Nnamdi Kohn <> nnamdi.kohn@tu-bs.de> > wrote:
I am trying to navigate within the file system using C programming. Here I
use system( “cd [folder]” ) e.g. to navigate into a desired folder.

use chdir() instead of system()…

Or, if you insist on using system(), try redirecting its standard output
and standard error elsewhere…

But system(“cd folder”) is not going to change your program’s directory.
It’s going to start a shell that changes its directory and then exits.