system("cd ..");

system("cd ..");

Post by Martin Schmid » Wed, 31 Jan 2001 18:57:53



I want to change a directory from within a program ,
i tried the following :

#include <stdio.h>
#include <stdlib.h>

main()
{
  system("cd ..");
  system("pwd");
  return 0;

Quote:}

This will not work (because system uses fork and execxx ?) .
I tried to use instead :
system(". cd ..");
which will not work either , to start cd with a leading point seems
to be impossible .
Does anyone know how it can be done ?

Thanks in advance,
Martin

 
 
 

system("cd ..");

Post by Alan » Wed, 31 Jan 2001 19:26:47



> This will not work (because system uses fork and execxx ?) .
> I tried to use instead :
> system(". cd ..");
> which will not work either , to start cd with a leading point seems
> to be impossible .
> Does anyone know how it can be done ?

Try this

#include <stdio.h>
#include <stdlib.h>

main()
{
  char buff[255];

  printf("%s\n", getcwd(buff, 255));
  chdir("/");
  printf("%s\n", getcwd(buff, 255));

  return 0;

Quote:}

> Thanks in advance,
> Martin


 
 
 

system("cd ..");

Post by Floyd Davidso » Wed, 31 Jan 2001 19:38:44



>I want to change a directory from within a program ,
>i tried the following :

>#include <stdio.h>
>#include <stdlib.h>

>main()
>{
>  system("cd ..");
>  system("pwd");
>  return 0;
>}

>This will not work (because system uses fork and execxx ?) .
>I tried to use instead :
>system(". cd ..");
>which will not work either , to start cd with a leading point seems
>to be impossible .
>Does anyone know how it can be done ?

There is no escaping the fact that system() function uses a
subshell to execute the argument as a command.

Do "man 2 chdir" for a system call to change the current working
directory directory.

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>

 
 
 

system("cd ..");

Post by Erik Max Franci » Thu, 01 Feb 2001 05:33:43



> Does anyone know how it can be done ?

man chdir

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Too much agreement kills a chat.
\__/ Eldridge Cleaver
    Product's Quake III Arena Tips / http://www.bosskey.net/
 Tips and tricks from the absolute beginner to the Arena Master.

 
 
 

system("cd ..");

Post by Donovan Rebbec » Thu, 01 Feb 2001 18:07:34



>I want to change a directory from within a program ,
>i tried the following :

General advice : avoid the temptation to do this:
        system (" some familiar command" );
C is not bourne shell script.

See man chdir for information on how to do it properly.

--
Donovan Rebbechi * http://pegasus.rutgers.edu/~elflord/ *
elflord at panix dot com

 
 
 

1. Type "(", ")" and "{", "}" in X...

Hi,

When i start a shell under X, i can type all characters on my keyboard,
the same when i start the simple editor, but when i start Forte (Java
IDE) written in Java i cant use the "(", ")", "{", "}" and allmost none
of the characters that are located on the same key as a number...

Does anybody have an idea what i can do about that... could it be
something with programs written in Java..?

Mvg,
Erwin

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Warez?

3. GETSERVBYNAME()????????????????????"""""""""""""

4. How to change the IP Address in Solaris 7.0

5. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

6. add support for PC-9800 architecture (PCI)

7. where can I ftp "metaconfig" (generator of "Configure")?

8. need help with lpd

9. Definition of "word" in zsh (e.g., "backward-kill-word")

10. pccardd[49]: No card in database for "(null)"("(null)")

11. "?" in html text (e.g. "This is Adam?s post")

12. Sun Workshop C Compiler ("char" as "unsigned char") ?

13. Why does "cd /usr/////bin" = "cd /usr/bin"?