0

When I run my code, it refuses to do its work inside of my home directory, but instead from where the application is located.

system("cd ~");
system("curl https://www.dropbox.com/s/5zbfuog50rlztil/Archive.zip > tmp.zip");
system("unzip tmp.zip");

The file isn't put in the right location so the remainder of the program will not execute properly.

2 Answers2

3

system() starts a shell to perform the command, then leaves the shell.

So the cd is performed and as the shell ends it is forgotten.

So to solve your specific issue:

Place all three commands in one script and execute it with one call to system().

alk
  • 69,737
  • 10
  • 105
  • 255
  • Ok thank you, rewriting this code to not rely on the cd should work then? –  Jan 03 '13 at 07:48
  • 1
    @MarkRobinson Yes. Or do it in one shell `system("cd ; curl https://www.dropbox.com/s/5zbfuog50rlztil/Archive.zip > tmp.zip"); – nos Jan 03 '13 at 07:50
0

You can also do the following

system("curl https://www.dropbox.com/s/5zbfuog50rlztil/Archive.zip > $HOME/tmp.zip");
system("unzip $HOME/tmp.zip -d $HOME/");

BTW, you should check for errors

Yann Droneaud
  • 5,277
  • 1
  • 23
  • 39