Solved

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

Posted on 2003-12-01
6
305 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

773 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