run time.bat through C programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anugrahbala10
    New Member
    • Mar 2013
    • 13

    run time.bat through C programming

    i want to run time.bat through C programming i used system command in this way :-
    Code:
    *-----------------**---------------------------------
    //(time.bat file)
    @echo on
    time
    @echo off
    **---------------------**------------------------------
    the problem is the program is running correctly with no error in compiling but showing only clear output screen and ma time.bat batch is not running what shall i do to run that file in c ?? please help me:'(

    Code:
    #include<stdio.h>
    #include<process.h>
    #include<stdio.h>
    
    void main(){
     print("calling time.bat\n");
     system("E:\TURBO\BIN\time.bat");
    }
    Last edited by acoder; Mar 24 '13, 11:20 AM. Reason: Please use [code] tags when posting code
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Have you tried:

    Code:
    system("E:\\TURBO\\BIN\\time.bat");
    The \ is a preprocessor escape sequence. The character following the \ is a code. So you need a \\ to force the \ you need in your path.

    Comment

    • anugrahbala10
      New Member
      • Mar 2013
      • 13

      #3
      Sir i did the way u said bt stil i have same problem:-(

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        I suspect yur progaram is running so fast all you see is a black screen for a split second.

        Insert a getchar() after your system call. That will halt the program until you press enter. This will give you time to read what's on the screen.

        Comment

        • anugrahbala10
          New Member
          • Mar 2013
          • 13

          #5
          Thank you so much sir it works..sir i called two .bat files together how can i make the time diffrence between both the call?

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Exactly what are trying to measure? How long your .bat file takes? Or something else?

            Comment

            • anugrahbala10
              New Member
              • Mar 2013
              • 13

              #7
              i just want to make a time delay in opening between two ".bat" files by code for eg
              open "time.bat" nd after 5 sec open "sys.bat"?

              Comment

              • weaknessforcats
                Recognized Expert Expert
                • Mar 2007
                • 9214

                #8
                There is a sleep function that will pause your program for a nuber of seconds:

                Code:
                sleep(5);  /*wait 5 seconds */
                It is not a ANSI standard function so you may not hve access to it. If not, you can write your own sleep function:

                1)Pass in the number of seconds to wait
                2)clock the system clock. This is your start time
                3)start a do loop
                4)inside the loop clock the system clock. This is your current time.
                5) stay in the loop as longs as start time+wait seconds is less then the current time.
                6) return when you drop out of the loop.

                Comment

                Working...