[Rookie] Date-Function, calling external files

R

Raskolnikow

Hi!

I have some beginner questions about C++,
so please be gentle if the things I ask are trivial.

What I want to do is a program that
- changes the current (system) date,
- calls an external program and
- resets the system date again (after a delay).

I have just written that in Java, but I wanted it to
be a small and nice tool (i.e. without loading the VM)
in C or C++.
Unfortunately I have only Borland C++ 5.5 and
TurboC 2.0. Which compiler options can I use to
make the executable as small as possible ?

So here is an excerpt from my java prog:

public final class DateChange {
private static Process proc;

public static void main(String[] args) {
if (args == null || args.length < 2) {
System.out.println("SYNTAX: DateChange <FileName> <Date>");
System.exit(1);
}

String command = args[0];
String targetDate = args[1];

Date date = new Date();
String currentDate = date.toLocaleString().substring(0,10); // this is
DD/MM/YYYY
Runtime runtime = Runtime.getRuntime();

try {
proc = runtime.exec("command.com /c date " + targetDate);
proc = runtime.exec(command);
// waiting for the program to start up
Thread.sleep(5000);
proc = runtime.exec("command.com /c date " + currentDate);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
}

System.exit(0);
}
}

Thanks a lot !

Cheers,
Bernhard
 
M

Michiel Salters

Raskolnikow said:
Hi!

I have some beginner questions about C++,
so please be gentle if the things I ask are trivial.

What I want to do is a program that
- changes the current (system) date,
- calls an external program and
- resets the system date again (after a delay).

I have just written that in Java,

try {
proc = runtime.exec("command.com /c date " + targetDate);

It looks like you need the system() call in C and C++

Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top