I have a cgi program in c where I am using a system call for getting the present working directory (pwd). I used system(pwd);
, but this will print the directory name on screen(html) which I don't need as of now.
Is there any way to make the system () function not to display anything,? (Something similar to shell_exec() in php where the output is displayed only when we need it to be displayed)..
Asked
Active
Viewed 200 times
3

user2723949
- 289
- 2
- 4
- 10
-
1It's unclear what you want. If you want to silence the command, you can redirect the command output to "/dev/null". In your case, why not simply comment out the line altogether? – Eitan T Oct 29 '13 at 08:29
-
2Maybe `system("pwd > /dev/null 2>&1");`? – devnull Oct 29 '13 at 08:30
-
To get the current work directory from a C rpgoram you might like to use `getcwd()`. – alk Oct 29 '13 at 08:32
-
@devnull: Isn't this a NOP? (besides testing whether `pwd` is available and working) – alk Oct 29 '13 at 08:33
-
@alk This __is__ a no-op. The assumption was that the OP is executing a command that has a side-effect and produces output that needs to be ignored. – devnull Oct 29 '13 at 08:35
-
@devnull You got it! and +1 for the command.. – user2723949 Oct 29 '13 at 11:13
1 Answers
0
Looks like you are on a Linux/Unix system.
You can get the pwd from the environment, you don't need to use system
:
#include <stdlib.h>
char *pwd = getenv("PWD");
For your reference, here is one example on how you can get the output from system
(there are other ways):

Community
- 1
- 1

Klas Lindbäck
- 33,105
- 5
- 57
- 82