That pipe character (|
) means that the output from sudo apt-get update
is being piped into the input of sudo apt-get -y install apache2 zip unzip
. Although this doesn't actually make any sense, it does mean both get launched at the same time, which is not what you want.
Either replace the single call with two individual system() calls:
system("sudo apt-get update");
system("sudo apt-get -y install apache2 zip unzip");
Note that when you call system(), your program doesn't resume until the process you launched has exited, so this means the first call will execute, then the second.
Or replace the pipe with &&
(isn't necessarily guaranteed to work, though it really should on any Linux system):
system("sudo apt-get update && sudo apt-get -y install apache2 zip unzip");
Which means the right-hand side of the command will execute only if the left-hand side exits without error (technically, has an exit status of 0).
You can also replace the pipe with a semicolon (;
) instead, which should execute both commands in sequence regardless of the exit status of the first command.