redirect a spawned process's output, or how to read ZIP

This is a discussion on redirect a spawned process's output, or how to read ZIP within the C Programming forums, part of the General Programming Boards category; Is there a way to read the contents of a zip file in C? I just need the file list, ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831

    redirect a spawned process's output, or how to read ZIP

    Is there a way to read the contents of a zip file in C? I just need the file list, dates, sizes.

    I realize I can
    Code:
    strcpy(this_path, "WZZIP");
    
    	ret = _spawnl(P_WAIT, this_path, this_path, "-vbf", "test.zip", ">temp", NULL);
    This does work up to a point. but the redirect does not work so I can not capture the program's output. I looked all over the place for how to set a spawned process's stdout but found no solution when using spawn().

    ... or pipe, or whatever (would be faster than intermediate temporary file, or could be the same)

    I am perfectly willing to see any other easier way to read a ZIP file.

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I've never done this in Windows, so maybe I'm missing something, but...

    the redirect does not work so I can not capture the program's output
    Redirecting only redirects stdout (i.e. anything they print with printf, etc).. An unzipping utility will specify new files to create and write to those - redirection doesn't work in that case.

    So if you unzipped a file (using a separate utility) it would be best to unzip it to a temporary location and use that in your program. There may of course be libraries written for C to do this more cleanly, but I'm not familiar with any of them to give you recommendations. (Standard C does not provide for this - you either need an unzipping library from someone else, a separate program that does it all, or you'd need to learn the file format and write your own - the latter would be extremely difficult!)

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by nonoob View Post
    Is there a way to read the contents of a zip file in C?
    Try zziplib, in particular the zzip_opendir, and zzip_readdir functions should be of interest to you.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    sean, no it's not an unzipping utility that I'm interested in. It so happens that the WinZip console .exe tool WZZIP can do that, but I'm just using it to dump a list of file names contained within the zip file (hence the flag -v). Sorry if that wasn't clear. It spews the list alright when I execute it in a console window, and it also redirects happily to a temp file using ">"... but the issue is when using spawn(). Can't seem to capture the tool's output.

    Thanks, MWAAAHAAA , I'll take a look at that.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    Check out this thread (scroll down to post #3). I'm pretty sure popen will work for something like this.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to redirect the output of a program?
    By dkt in forum C Programming
    Replies: 2
    Last Post: 04-25-2002, 12:05 AM
  2. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM
  3. Replies: 1
    Last Post: 12-31-2001, 04:04 PM
  4. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM
  5. To all who read last post formatted output
    By spliff in forum C Programming
    Replies: 8
    Last Post: 08-21-2001, 03:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21