Hello,

I need to write a script for a program I am running and I have never written on. I don't even know what commands scripts use, or what they even look like. Does anyone know any tutorials or example I could modify to fit my needs? Thanks,

-Al

"Script" is a very broad term that typically doesn't apply to C or C++. Can you be more specific?

I have a random number generator which outputs a file that my program uses. I want to be able to write something so that I don't have to manually execute the random number generator and then manually move the file to where the program need it. Pretty much have the random number generator and the program to run without having me execute them each time. I am only familliar with c++, I do not know any pearl. I hope this is more clear.

-Al

Write a separate C++ program that creates the file and places it where you want. Basic automation. :)

My problem is to have the program execute pretty much indefinitely while I'm away. Pretty much...
Random number--->move file--->run program--->repeat

Here:

while(1)
{
     //your code here
}

What will that do?

Here:

while(1)
{
     //your code here
}

The program I am running is a Fortran program. What is does is run a simulation. I have a code that outputs a file for the fortran program, and when it has that program I run the simulation. The simulation roughly an hour to run, what I am trying to do is have the program continue to run for about 2 months without me having to execute the program each time. I pretty much want something where I can start it one day, and check on it a week later or something to that extent.

Why are you asking about scripts and fortran in a C++ forum?

I know essentially no nothing about writing scripts, I was led to believe I could write a script in c++ (the only language I know). All I need to do is execute the fortran program, nothing more than that. From everyone's responses I take it you can't write a script in c++, I'm just trying to figure out what I need to do because I am in the dark. Thanks, sorry for frustrating anyone out there.

-Al

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
       int num = rand();
       ofstream cFile;
       cFile.open("RanNum.txt");

       loop:
       cFile << num << endl;
       goto loop;
}

A very simple way of doing it which can eventualy overload your computer (I think). However, I'm confused how you want to move the file.

umm what's with the unneeded goto is while(1) not good enough anymore?

umm what's with the unneeded goto is while(1) not good enough anymore?

I have to agree with prog-man (again). The goto should only be used to get out of deeply nested loops, otherwise it is considered bad style.

I agree as well, however I chose goto so I did not have to fix the spacing (I cannot use tab on this text box). Lame excuse and write-up I know. :eek:

Anyways, to make up for it:

#include <iostream>
#include <fstream>
#include <stdio.h>

#using <mscorlib.dll>

using namespace System;
using namespace System::IO;

using namespace std;

int main()
{
	string* NewPath = S"C:\\File.txt"; // Your path
	string* OldPath = String::Concat(NewPath, S"temp");

	ofstream cFile;
	cFile.open("File.txt");	// or should it be NewPath? Not quite sure...
	
	int num = rand();
	
	try
	{

		if (!File::Exists(NewPath))
			File::Move(OldPath, NewPath);
	}


	while(1) 	// For you prog-bman : )
		cFile << num << endl;
}

Hopefully I did not mess up anywhere in this. I used notepad this time : )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.