Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-12-01
6
Medium Priority
?
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 700 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 700 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

670 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