473,385 Members | 1,673 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,385 software developers and data experts.

[system]



I'll just be in and out with a quick question.

If you have an unzip32.exe and a.zip in the same directory as the ensuing
executable, what source in c++ imitates the following pseudo-source:

#include <stdio.h>

int main(void)

system " unzip32 " "a.zip"

end program

I have another question:

What's new and nice in c plus plus?

--
Richard Milhous Nixon

A good memory and a tongue tied in the middle is a combination which gives
immortality to conversation.
~~ Mark Twain
Oct 15 '08 #1
4 1637
Richard Nixon wrote:
If you have an unzip32.exe and a.zip in the same directory as the ensuing
executable, what source in c++ imitates the following pseudo-source:

#include <stdio.h>

int main(void)

system " unzip32 " "a.zip"

end program
I believe 'system' is declared in <stdlib.h>, not <stdio.h(that's in
C, BTW). So, add a couple of curly braces and parentheses and you might
even get your program right there...

#include <stdlib.h>

int main(void)
{
system("unzip32 a.zip");
return 0;
}

Whether it imitates anything or not, I am not sure. The behaviour of
the 'system' function is implementation-defined, so nothing really we
can say for sure of the outcome of that program. Sorry about that!
I have another question:

What's new and nice in c plus plus?
Many things. How many years are you prepared to spend learning them?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 15 '08 #2
On Oct 15, 4:14 am, Victor Bazarov <v.Abaza...@comAcast.netwrote:
Richard Nixon wrote:
If you have an unzip32.exe and a.zip in the same directory
as the ensuing executable, what source in c++ imitates the
following pseudo-source:
#include <stdio.h>
int main(void)
system " unzip32 " "a.zip"
end program
I believe 'system' is declared in <stdlib.h>, not <stdio.h>
(that's in C, BTW).
There's a <stdlib.hin C++ as well. And a <cstdlibwith
std::system, for those who prefer it.
So, add a couple of curly braces and parentheses and you might
even get your program right there...
#include <stdlib.h>
int main(void)
{
system("unzip32 a.zip");
return 0;
}
Whether it imitates anything or not, I am not sure. The
behaviour of the 'system' function is implementation-defined,
so nothing really we can say for sure of the outcome of that
program. Sorry about that!
Well, he sort of provided the system dependent part. The real
problem he'll probably run into is that unzip32.exe and a.zip
are in the same directory as his executable, which is not
necessarily the diretory in which his code is running. There's
definitely nothing in C++ which supports finding where the
executable was actually started. The closest you can come is to
try parsing argv[0] (which is supposed to contain the name used
to invoke the program---but in practice doesn't always), then
emulating the way the system looks up executables---a lot of
work, not completely portable, and in practice, not necessarily
reliable. On specific platforms, you may have something in the
system API which would help (try GetModuleFileNameEx(
GetCurrentProcess(), NULL, ... ) under Windows---I don't know of
anything similar under Unix, however).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 15 '08 #3
James Kanze <ja*********@gmail.comkirjutas:
There's
definitely nothing in C++ which supports finding where the
executable was actually started. The closest you can come is to
try parsing argv[0] (which is supposed to contain the name used
to invoke the program---but in practice doesn't always), then
emulating the way the system looks up executables---a lot of
work, not completely portable, and in practice, not necessarily
reliable. On specific platforms, you may have something in the
system API which would help (try GetModuleFileNameEx(
GetCurrentProcess(), NULL, ... ) under Windows---I don't know of
anything similar under Unix, however).
In general, there is no way to relate an (unstarted executable, or any
other) file to a certain directory. In Unix filesystems there are
hardlinks and mounts, and on Windows there are subst commands, network
drive mapping, etc, which mean that the same file can have multiple
directory paths. However, when launching the application, the kernel
finds it in a certain directory path, and this information might be
useful for the application. Windows makes it available through the
GetModuleFileName[Ex]() function (as you said) and Linux makes it
available through the /proc/PID/exe or /proc/self/exe, which is probably
more reliable than argv[0]. In both cases this is a piece of dynamic
information related to the process creation by the kernel.

Paavo

Oct 22 '08 #4
On Oct 23, 12:28 am, Paavo Helde <nob...@ebi.eewrote:
James Kanze <james.ka...@gmail.comkirjutas:
There's definitely nothing in C++ which supports finding
where the executable was actually started. The closest you
can come is to try parsing argv[0] (which is supposed to
contain the name used to invoke the program---but in
practice doesn't always), then emulating the way the system
looks up executables---a lot of work, not completely
portable, and in practice, not necessarily reliable. On
specific platforms, you may have something in the system API
which would help (try GetModuleFileNameEx(
GetCurrentProcess(), NULL, ... ) under Windows---I don't
know of anything similar under Unix, however).
In general, there is no way to relate an (unstarted
executable, or any other) file to a certain directory.
Portably. For a number of systems (including Windows and most
Unix), there is a system specific way, but it's not portable;
even within the Unix community, different Unix may do it
differently.
In Unix filesystems there are hardlinks and mounts, and on
Windows there are subst commands, network drive mapping, etc,
which mean that the same file can have multiple directory
paths.
Which isn't necessarily a problem, as long as you can find one
of them.
However, when launching the application, the kernel finds it
in a certain directory path, and this information might be
useful for the application. Windows makes it available through
the GetModuleFileName[Ex]() function (as you said) and Linux
makes it available through the /proc/PID/exe or
/proc/self/exe, which is probably more reliable than argv[0].
But is pure Linux; there's no /proc/self under Solaris, for
example.

For some programs, it might be sufficient to search for argv[0]
in PATH environment variable; it's certainly not 100% reliable,
but it will cover a lot of use case scenarios. Of course, you
still have the portability issue that the path separator under
Unix is :, under Windows ;, and that the directory separator
must be / under Unix, but can be either \ or / under Windows
(and that an initial <alpha>: has a special meaning, and that
some files systems are case insensitive, others case sensitive).

If you control the installation, of course, the simplest
solution under Windows is to put such information in the
registry, during installation. Under Unix, a lot of programs
require you to set an environment variable, something like
MYPROG_HOME, which specifies the installation root.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 23 '08 #5

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

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
2
by: Scott | last post by:
Not sure if this is the right place to post this or not, but I am in the process of trying to find a Web Hosting/Isp Billing system that is reasonable in price and uses Access or SQL Server for a...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
1
by: Sky | last post by:
Yesterday I was told that GetType(string) should not just be with a Type, but be Type, AssemblyName. Fair enough, get the reason. (Finally!). As long as it doesn't cause tech support problems...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
2
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, I am wondering why the .NET Framework is quite different from Win32 API when it comes to displaying system modal message boxes. Consider the four following types of system modal message...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.