Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > system() Statuscode

Reply
Thread Tools

system() Statuscode

 
 
Frank Liebelt
Guest
Posts: n/a
 
      03-08-2006
Hi

I am a beginner in c++.

In my little program i would unpack a tar file with a system call.
system("tar -xfv unpack.tar");

Is it possible to check that the tar command was successfull or not?
I know system() gives -1 on error, 0 on OK but how to check tar was
successfull?

I thought about if (access(... but i hope there is a better way to do this.

Frank
 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      03-08-2006
Frank Liebelt wrote:

> In my little program i would unpack a tar file with a system call.
> system("tar -xfv unpack.tar");
>
> Is it possible to check that the tar command was successfull or not?
> I know system() gives -1 on error, 0 on OK but how to check tar was
> successfull?


Use popen (or _popen), and read each line returned from the call. Parse the
line to find success or failure indicators. Then use pclose to get the final
return value.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


 
Reply With Quote
 
 
 
 
Frank Liebelt
Guest
Posts: n/a
 
      03-08-2006
Phlip wrote:
> Frank Liebelt wrote:
>
>> In my little program i would unpack a tar file with a system call.
>> system("tar -xfv unpack.tar");
>>
>> Is it possible to check that the tar command was successfull or not?
>> I know system() gives -1 on error, 0 on OK but how to check tar was
>> successfull?

>
> Use popen (or _popen), and read each line returned from the call. Parse the
> line to find success or failure indicators. Then use pclose to get the final
> return value.
>



I tried this but it wont work:

bool unpack(int value)
{
FILE *tar;
char buf[128];

switch (value)
{
case 1:
if ((tar = popen("tar -xf /tmp/mytar.tar -C /home/user1", "rt")) == NULL)
return false

if (pclose(tar) == 0)
return true;

return false;
break;
}
case 2:
if ((tar = popen("tar -xf /tmp/mytar.tar -C /home/user2", "rt")) == NULL)
return false

if (pclose(tar) == 0)
return true;

return false;
break;
}

}

It doesnt work cause this gives allways false
if ((tar = popen("tar -xf /tmp/mytar.tar -C /home/user", "rt")) == NULL)

tar is installed an this command works in the console with no probs.

Frank
 
Reply With Quote
 
Aaron Isotton
Guest
Posts: n/a
 
      03-08-2006
Frank Liebelt wrote:
> It doesnt work cause this gives allways false
> if ((tar = popen("tar -xf /tmp/mytar.tar -C /home/user", "rt")) == NULL)
>
> tar is installed an this command works in the console with no probs.


Maybe you need to give the full path of tar. Anyway, that's rather a
question for comp.unix.programmer.

Greetings,
Aaron
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
return HttpStatusCode.ServiceUnavailable in the context.context.Response.StatusCode (Http response code 503) Flip Rayner ASP .Net 1 01-23-2007 06:35 AM
custom error page for Statuscode 401.2 - Access Denied Rich ASP .Net 1 05-26-2005 03:24 PM
Confused about Response.StatusCode Shane ASP .Net 1 11-21-2003 11:27 AM
Response.StatusCode Shane ASP .Net 0 11-20-2003 04:44 PM
CustomErrors statusCode 500 Jesse Napier ASP .Net 3 08-07-2003 09:07 PM



Advertisments