2 Replies - 1338 Views - Last Post: 25 April 2011 - 05:36 AM Rate Topic: -----

#1 bissan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-April 11

Run a c++ program in the background

Posted 25 April 2011 - 05:24 AM

hey guys ,

im working on a program that sends values (extracted from an XML file ) to a website

i need to know if i can run the program in the background every 30 min is that possible in c++
here is my code (its completely running)

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include "conio.h"
#include <stdlib.h>
#include <windows.h>
#include <Shellapi.h>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	ifstream in("C:\\\Users\\\Maya\\\Desktop\\\G5317575.XML",ios::in);
	ifstream fin("C:\\\Users\\\Maya\\\Desktop\\\dandt.txt");
	if (!in) {
		cerr << "ERRRRRRRRRRRRRRRRRRRRR" << endl;
	}
	string textline;
	string past_date;
	string past_time;
	while (!fin.eof()) {
		getline(fin, textline, '\n');
		if(textline.length() > 5)
			past_date = textline;
		if(textline.length()==5)
		past_time = textline;
	}
	fin.close();
	cout << "PAST DATE: " << past_date << endl;
	cout << "PAST TIME: " << past_time << endl;
	string line;
	string value;
	string SN;
	string unit;
	string recdate;
	string rectime;
	string dateinbg;
	string timeinbg;
	string web = ("http:/bnm.web44.net/inserttest.php?value=");
	string andSN = ("&SN=");
	string anddate = ("&date=");
	string andtime = ("&time=");
	string andunit = ("&unit=");


	while (!in.eof()) {
		getline(in, line, '\n');
		cout << line << line.length() << endl;
		if (line.length() > 4) {
				if(line[0]== '<' && line[1]== 'R' && line[2]== 'E' && line[3]=='C'){
				recdate = line.substr(15,10);
				cout << "Date is: " << recdate << endl;
				rectime = line.substr(31,5);
				cout << "Time is: " << rectime << endl;
			}
			if(line[0]== '<' && line[1]== 'D' && line[2]== 'E' && line[3]=='V'){
				SN = line.substr(29,8);
				cout << "SN: "<< SN;
				cout << endl;
				unit = line.substr(74,5);
				cout << "UNIT: " << unit;
				cout << endl;
			}
		if (line[0] == '<' && line[1] == 'B' && line[2] == 'G' && line[3] == ' ') {
				int c=9;
				while (line[c] != '"')
					c++;
				c--;
				value = line.substr(9,c+1-9);
				cout<<"VALUE is ="<<value<<endl;
				int d=17;
				if(line[d]== '"'){
					dateinbg=line.substr(18,10);
					cout << "Date in BG: " << dateinbg << endl;
					timeinbg = line.substr(34,5);
					cout << "Time in BG: " << timeinbg << endl;
				}
				else{
				dateinbg = line.substr(17,10);
				cout << "Date in BG: " << dateinbg << endl;
				timeinbg = line.substr(33,5);
				cout << "Time in BG: " << timeinbg << endl;
				}
				if(dateinbg != past_date && timeinbg!= past_time){
					web.append(value);
					web.append(andSN);
					web.append(SN);
					web.append(anddate);
					web.append(dateinbg);
					web.append(andtime);
					web.append(timeinbg);
					web.append(andunit);
					web.append(unit);
					char *cstr;
					cstr = new char [web.size()+1];
					strcpy (cstr, web.c_str());
					if(ShellExecute(NULL, _T("open"), cstr , NULL, NULL, SW_SHOWNORMAL)) 
					web = ("http:/bnm.web44.net/inserttest.php?value=");
				}
				if(dateinbg == past_date && timeinbg == past_time){
					break; }
				
			}
				
		}
	
		
		}
	in.close();
	ofstream fout("C:\\\Users\\\Maya\\\Desktop\\\dandt.txt");
	fout << recdate << endl;
	fout << rectime << endl;
	fout.close();
	getch();
	return 0;

}


thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Run a c++ program in the background

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Run a c++ program in the background

Posted 25 April 2011 - 05:36 AM

Windows Scheduled Tasks
Was This Post Helpful? 1
  • +
  • -

#3 Hezekiah   User is offline

  • D.I.C Addict
  • member icon

Reputation: 208
  • View blog
  • Posts: 552
  • Joined: 12-July 09

Re: Run a c++ program in the background

Posted 25 April 2011 - 05:36 AM

You could either keep the program running and program it to do something every 30 minutes (have a look at the ctime header) or configure Windows to run it every 30 minutes. Can't help you with the last one, though.

Edit: JackOfAllTrades beat me. Have a look at his link.

This post has been edited by Hezekiah: 25 April 2011 - 05:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1