Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Running a batch file

Running a batch file

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Camron
    wrote on last edited by
    #1

    I'm trying to write a program that will initiate a batch file. For some reason the program keeps crashing. I'm not too familiar with the createprocess function so I figure I'm doing something wrong with that. To run the program in a DOS prompt I must be in the path U://telmage/ To run the process I type telmage 09 19 05 or the previous days date. Does anyone have any idea what I might be doing wrong? [CODE] void main() { char path_buffer[_MAX_PATH]; char GTime[80]; time_t now; UINT value; now = time(NULL); time_t yesterday = now - 86400; strftime(GTime,sizeof GTime,"telmage %m %d %y",localtime(&yesterday)); _makepath( path_buffer, "U", "\\telmage", GTime, "" ); cout<

    D B C J 4 Replies Last reply
    0
    • C Camron

      I'm trying to write a program that will initiate a batch file. For some reason the program keeps crashing. I'm not too familiar with the createprocess function so I figure I'm doing something wrong with that. To run the program in a DOS prompt I must be in the path U://telmage/ To run the process I type telmage 09 19 05 or the previous days date. Does anyone have any idea what I might be doing wrong? [CODE] void main() { char path_buffer[_MAX_PATH]; char GTime[80]; time_t now; UINT value; now = time(NULL); time_t yesterday = now - 86400; strftime(GTime,sizeof GTime,"telmage %m %d %y",localtime(&yesterday)); _makepath( path_buffer, "U", "\\telmage", GTime, "" ); cout<

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      I would create a .bat file with the following commands in it: U: cd \telmage telmage 09 19 05 and then call CreateProcess() specifying the .bat file as the command to run.


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      C 1 Reply Last reply
      0
      • D David Crow

        I would create a .bat file with the following commands in it: U: cd \telmage telmage 09 19 05 and then call CreateProcess() specifying the .bat file as the command to run.


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

        C Offline
        C Offline
        Camron
        wrote on last edited by
        #3

        So what you're saying is write a batch file that will take in the date and then call the original batch file to run? That makes sense but why can the original batch file be called from the prog? Also this is something I am wanting to be automated and run every day. So I can't just have a static date.

        D 1 Reply Last reply
        0
        • C Camron

          So what you're saying is write a batch file that will take in the date and then call the original batch file to run? That makes sense but why can the original batch file be called from the prog? Also this is something I am wanting to be automated and run every day. So I can't just have a static date.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Camron wrote: So what you're saying is write a batch file that will take in the date and then call the original batch file to run? No. The batch file you create at runtime will contain those commands that you would otherwise issue at a command prompt. Camron wrote: That makes sense but why can the original batch file be called from the prog? I assume you mean why can't it be called from the program. It can with a fair amount of finagling. I find it much easier to do it this way. Camron wrote: Also this is something I am wanting to be automated and run every day. So I can't just have a static date. No need to. You create the .bat file each time you need it, specifying a different date each time. When you are all done, simply remove the .bat file.


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          1 Reply Last reply
          0
          • C Camron

            I'm trying to write a program that will initiate a batch file. For some reason the program keeps crashing. I'm not too familiar with the createprocess function so I figure I'm doing something wrong with that. To run the program in a DOS prompt I must be in the path U://telmage/ To run the process I type telmage 09 19 05 or the previous days date. Does anyone have any idea what I might be doing wrong? [CODE] void main() { char path_buffer[_MAX_PATH]; char GTime[80]; time_t now; UINT value; now = time(NULL); time_t yesterday = now - 86400; strftime(GTime,sizeof GTime,"telmage %m %d %y",localtime(&yesterday)); _makepath( path_buffer, "U", "\\telmage", GTime, "" ); cout<

            B Offline
            B Offline
            bugDanny
            wrote on last edited by
            #5

            I'm not sure why you need to use CreateProcess. And why not programmatically create the batch file each time? For example, #include <fstream.h> fstream batchFile; batchFile.open("Launch.bat", ios::out); if(!batchFile){ /* Uh-oh! */ } batchFile << "U:" << endl; batchFile << "cd \\telmage" << endl; strftime(GTime, sizeof(GTime), "%m %d %y", localtime(&yesterday)); batchFile << "telmage " << GTime << endl; batchFile.close(); if(WinExec("Launch.bat", 0) < 32){ // Something went wrong } //I think you toggle the 0 to 1 in the WinExec call if you // want the resulting process to be visible. // Add code here to delete "Launch.bat" if you so desire. This code works like DavidCrow suggests, with a batch file calling the original batch file, only you won't have to recreate the calling batch file every day by hand. Hope this helps! Danny -- modified at 13:16 Tuesday 20th September, 2005

            1 Reply Last reply
            0
            • C Camron

              I'm trying to write a program that will initiate a batch file. For some reason the program keeps crashing. I'm not too familiar with the createprocess function so I figure I'm doing something wrong with that. To run the program in a DOS prompt I must be in the path U://telmage/ To run the process I type telmage 09 19 05 or the previous days date. Does anyone have any idea what I might be doing wrong? [CODE] void main() { char path_buffer[_MAX_PATH]; char GTime[80]; time_t now; UINT value; now = time(NULL); time_t yesterday = now - 86400; strftime(GTime,sizeof GTime,"telmage %m %d %y",localtime(&yesterday)); _makepath( path_buffer, "U", "\\telmage", GTime, "" ); cout<

              C Offline
              C Offline
              Christopher Lloyd
              wrote on last edited by
              #6

              I'm not sure the last two params of CreateProcess can be NULL - my SDK documentation certainly doesn't say that they can be. Maybe this is your problem?

              1 Reply Last reply
              0
              • C Camron

                I'm trying to write a program that will initiate a batch file. For some reason the program keeps crashing. I'm not too familiar with the createprocess function so I figure I'm doing something wrong with that. To run the program in a DOS prompt I must be in the path U://telmage/ To run the process I type telmage 09 19 05 or the previous days date. Does anyone have any idea what I might be doing wrong? [CODE] void main() { char path_buffer[_MAX_PATH]; char GTime[80]; time_t now; UINT value; now = time(NULL); time_t yesterday = now - 86400; strftime(GTime,sizeof GTime,"telmage %m %d %y",localtime(&yesterday)); _makepath( path_buffer, "U", "\\telmage", GTime, "" ); cout<

                J Offline
                J Offline
                Johann Gerell
                wrote on last edited by
                #7

                The process and startup info structures cannot be NULL. -- The Blog: Bits and Pieces

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups