Find the answer to your Linux question:
Results 1 to 5 of 5
I am trying to call gzip inside my c prog in Ubuntu with the system() function : system( "gzip file.dds" ); But nothing happens!The file is present in the current ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3

    [SOLVED] system() and gzip

    I am trying to call gzip inside my c prog in Ubuntu with the system() function :
    system( "gzip file.dds" );

    But nothing happens!The file is present in the current directory, and system() returns 0.
    If I call system( "gzip -h" ) instead, it does print the help message as intended.
    If I type the command by hand in the shell, it works.
    Same problem with zip : system( "zip tmp.zip file.dds" );

    Any idea somebody?
    Thanks.

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    try something like:

    system("gzip '/home/share/test/filename'");


    hope this helps...Gerard4143

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3
    Thanks for the answer Gerard, but still the same.
    I also tried to chmod 777 everything.
    It does not seem to be due to permissions.

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char**argv)
    {
    	system("gzip 'filename'");
    	exit(EXIT_SUCCESS);	
    }
    this is the code I used, both on Puppy Linux and Suse 11.0, and it worked with no problems

  5. #5
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3
    Ok, found my bug from your simplified code.
    I was building a command string with sprintf(), but passing system( "command" ), instead of system( command ).
    Isn't that great after a quarter century programming in C/C++ !
    Thanks again for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...