Solved

!!!!VERY VERY EASY!!!!!!

Posted on 2003-12-01
6
306 Views
Last Modified: 2010-04-01
Who can write for me a program, which reads a file(each line containing a date and something else(an action)), ececutes the action at the given time (I will write the actionpart)<br>
So the program reads the lines selects next date and time and calls a function at the given time.<br>Thanks
0
Comment
Question by:Centauri
6 Comments
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 175 total points
ID: 9851842
I can, but I wouldn't... because Windows and Linux both have the 'at' command.
0
 
LVL 69

Expert Comment

by:Callandor
ID: 9853209
Sounds like a job scheduler to me, so why would you want to reinvent the wheel?
0
 
LVL 1

Author Comment

by:Centauri
ID: 9856507
I need this because I would like to send information to an URL at that moment and I don't think, that it can be done without this program
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 175 total points
ID: 9857172
How about calling wget or curl (Linux) or lynx.exe (Windows) at the required time using at to schedule the batch file / script? The parameter can be picked up from a batch file /script.

e.g. In Windows XP you could maintain a file called value.txt with the URL-encoded value you wanted to send to http://xxx?This=value at 14:00 on Thursday.

   at 14:00 /next:THU "c:\MyStuff\DoIt.bat"

   DoIt.bat
   --------8<--------
   @echo off
   setlocal
   set /p that= < value.txt
   lynx -source "http://xxx?This=%that%" > c:\nul
   --------8<--------

...this sort of thing is easier in Linux.
0
 
LVL 69

Expert Comment

by:Callandor
ID: 9857969
Have you tried Control Panel->Scheduled Tasks->Add Scheduled Task and filling out the command to run on the Task tab and the time to run on the Schedule tab?  The command can be a perl script, DOS batch file, or exe file.  Why does this not work for you?
0
 
LVL 3

Accepted Solution

by:
RJSoft earned 125 total points
ID: 9858592
Semi-Pseudo code

struct SS
{
int date;
int time;
char DoIt[200];
};

// could do this as link list for larger instruction sets
// but this may be adaquate for you, I dont know

// space to read in 1000 instructions
struct SS Instruct[1000];

// load instructions and times into memory
FILE *fptr=NULL;
fptr=fopen("Input.txt","rb");
if(fptr==NULL)
{
MessageBox error....
return;
}//endif
int x=0;
while(1)
{
fread(&Instruct[x],sizeof(SS),1,fptr);
x++;
if(x==1000)break;
}//endwhile
fclose(fptr);

In InitDialog activate a timer

SetTimer(id,val,NULL);
Id can be any number dont matter,
val can be 1000 for fire every one second


Then use message member function OnTimer
from message WM_TIMER

void YourDialog::OnTimer(UINT Id)
{
//dont worry about id

//if date and time match do it...
if(Instruct[WhichInstruct].date==YourRequestedDate &&
   Instruct[WhichInstruct].time==YourRequestedTime )DoSomething();


}//endfunc


WhichInstruct could be a global variable to keep track of a count of which instruction got done last. So it could be a value of 0 to 999. You may only need 31 max, depending on what you want to do.

Once the DoSomething function runs you could increment the counter WhichInstruct++ for the next day. Going back to 0 for the begining of the month.

As far as creating the file simply load the struct with the values you like. You can use something more explicit than ints for date and time. up to you. Just after you load the struct use fwrite or whatever way you want to write the file.

fptr=fopen("file.txt","wb");
int x=0;
while(1)
{
prompt ("enter time");
Instruct[x].time=xxxxx;
prompt("enter date");
Instruct[x].date=yyyyy;
prompt("enter instruction"); //cin >> Str
strcpy(Instruct[x].DoIt,Str);   ex..."open first.htm"
fwrite(&Instruct,sizeof(SS),1,fptr);
x++;
if(prompt ...) break;
}//endwhile


void MyDialog::DoSomething()
{
// to open an html page
ShellExecute(Instruct[WhichInstruct],0,.....);
}//endfunc

One good thing about ShellExecute is that it does the instruction with the default program that is assigned to the specific file (in this case htm will start your browser)

Bad thing is that when the other app runs there is no real good way to shut the other app (browser in this case) down.

You can use EnumWindows to get the handle of your browser window and then close it, but thing is there is no standard amoung window titles and class names. (EnumWindows can get the title or class name for you but there are not much similarities enough to close unkown conditions)

Unless you know the classname and or window title specifically in each condition you will end up with other apps running uncontrolled. If this is acceptable then no need to worry hey...

You can also run another app and have your app wait for the processing of the other app to quit or terminate. You can do this with ShellExecute also but that may not really help in your case if your using an application like this for scripting purposes. This is because what good does it do you to run another application that does not close (like a browser) and have your scripting app just hang waiting for the other to close.....

If on the other hand your apps close after processing then this would be perfect.

RJ
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question