473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

system() Statuscode

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
Mar 8 '06 #1
3 2340
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!!!
Mar 8 '06 #2
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
Mar 8 '06 #3
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
Mar 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ad | last post by:
I use GenericErrorPage.aspx for the redirect page when some error occur. I want to show some different according error statusCode . How can I get error statusCode form Server.GetLastError()?
3
by: Jesse Napier | last post by:
I have a customerrors section in web.config something like the following: <customErrors mode="On" defaultRedirect="/errorPage/errorpage.aspx" > <error statusCode="404"...
0
by: Adrian Inman | last post by:
I have some image resizing code that resizes images and composites them with watermarks on the fly. I have integrated HTTP eTag aware caching with the code, however, the Response.StatusCode which I...
3
by: Keith Patrick | last post by:
I have the Beta 2 of VS 2005 running an ASP.Net 2.0 app. This thing worked yesterday, but today, it's telling me: Error 1 Could not load file or assembly 'System.EnterpriseServices,...
1
by: Adrian | last post by:
hi I'm attempting to build an app then sends a request to a URL and reads the response it works fine on my test site but when I connect to a real system I get the text below, I guess its...
0
by: Jim Duffie | last post by:
Hi, I am trying to build a simple websire using the above in Visual Web Developer. When finished I have build the website and it works fine locally but when I FTP it to the server I am getting a...
20
by: djc | last post by:
I get this *intermittently* on a utility I am working on. I don't know whats going on but here are a few points about it: - using VS 2005, running on xp sp2 - program uses multiple threadpool...
10
by: =?Utf-8?B?U3VzaGlTZWFu?= | last post by:
Hello. I need use http header StatusCode as response. For example my page have name check.aspx and I get request like this check.aspx?idcustomer=1395 I use this idcustomer param to check if this...
0
by: baburk | last post by:
Hi, I want to use the <customErrors> for all <system.web></system.web> If error occure this should be called. I have to write it once not in every <system.web></system.web>. How can I?
10
by: Anton | last post by:
Hi, when accessing a secured 3rd party webservice i'm getting a 401 HTTP Statuscode (unauthorized). When entering the url in a browser and entering the username and password manually, the wsdl is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.