[Rookie] Date-Function, calling external files

Discussion in 'C++' started by Raskolnikow, Jul 18, 2003.

  1. Raskolnikow

    Raskolnikow Guest

    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
    Raskolnikow, Jul 18, 2003
    #1
    1. Advertising

  2. "Raskolnikow" <> wrote in message news:<bf7ikq$cac57$-berlin.de>...
    > 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,


    <snip>

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


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

    Regards,
    --
    Michiel Salters
    Michiel Salters, Jul 18, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,250
    Michael Borgwardt
    May 30, 2004
  2. Brett
    Replies:
    4
    Views:
    382
    Dennis Lee Bieber
    Apr 15, 2005
  3. Sanjeeb
    Replies:
    2
    Views:
    181
  4. John Smith

    inner function calling external function

    John Smith, Mar 17, 2005, in forum: Javascript
    Replies:
    0
    Views:
    91
    John Smith
    Mar 17, 2005
  5. Mellow Crow
    Replies:
    6
    Views:
    417
    Richard Cornford
    Nov 4, 2005
Loading...

Share This Page