Running a batch file
-
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<
-
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<
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
-
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
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.
-
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.
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
-
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<
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 -
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<
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?
-
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<
The process and startup info structures cannot be NULL. -- The Blog: Bits and Pieces