LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-16-2008, 01:07 PM   #1
cyberfox007
LQ Newbie
 
Registered: Jan 2007
Distribution: Yellow Dog Linux v5.0
Posts: 8

Rep: Reputation: 0
Smile Help on Linux commands for a C++ code


Hey guys, noob at linux here

I have some c++ code that i wanna run through linux

My program accepts two command line arguments: an iteration count and a “sleep” time.

this is my code

Code:
//test.cpp

#include <iostream>
#include <time.h>
#include <stdio.h>
#include <cstdlib>
using namespace std;

void wait (int seconds)
{
  clock_t endwait;
  endwait = clock () + seconds * CLOCKS_PER_SEC ;
  while (clock() < endwait) {}
}

int main(int argc, char* argv[])
{
 time_t MainTime; 
 struct tm* InfoTime;
 int SleepNum, Times;
 int InputSpace[2];
 int i;

 for(i = 1; i < argc; i++)
   InputSpace[i-1] = atoi(argv[i]); 
 
 time(&MainTime);
 InfoTime = localtime(&MainTime);
 printf("Program started on %s\n", asctime(InfoTime));

 for(i = 1; i<=InputSpace[0]; i++)
 {
  cout << "\nRun Number " << i;
  cout << "\nWill Sleep for " << InputSpace[1]  <<" seconds\n";
  wait(InputSpace[i-1]);
 }

 time(&MainTime);
 InfoTime = localtime(&MainTime);
 printf("\nProgram ended on %s\n", asctime(InfoTime));
}
i gotta put in my command line something like: "text.exe 7 2(enter)"

my question is how do i run this program in the command line while putting these numbers at the end? (if i need to change any part of my code please let me know). do i need to go into the shell? how do i run it in the shell?

another question is how do i take what i see in the shell and copy it to a text file?

with that done i need to Find out the process ID of test.cpp, Find out all running processes that are related to the name test, While test is still running in one shell issue a command on the other shell that terminates it. and thats it.

Thanx!

Last edited by cyberfox007; 01-16-2008 at 01:09 PM.
 
Old 01-16-2008, 04:11 PM   #2
jakefolger
LQ Newbie
 
Registered: Nov 2007
Location: NJ
Distribution: Debian
Posts: 7

Rep: Reputation: 0
I don't quite understand your question but I'll give it a shot.

Your first step is to copy your program to your linux box. If you haven't done that yet I suggest emailing test.cpp as an attachment to yourself, moving to the linux box, opening a browser and downloading it to the desktop.

Once you have the file on your desktop open a shell.
type in "cd Desktop" and hit enter.
then type in "ls" and hit enter.

It should list the files on your desktop, and test.cpp should be there.

Next we need to compile your program.
To do that type "g++ test.cpp" and hit enter.

Hopefully it compiles. If not you have a problem with your code.

Once it compiles you'll want to run it.
To do this type in "./a.out [arg1] [arg2]" and hit enter (where [arg1] and [arg2] are your arguments you're sending to the program.

Hopefully that works as you intended. If everything works well up to this point you will want to direct the output to a file.
To do this type "./a.out [arg1] [arg2] > filename"

That should take all output that appeared on the screen the last time you ran the program and send it to a file named filename.

If you get this far let me know and we'll go over the last bit.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Source Code of the Linux commands drimades Linux - General 15 11-16-2006 05:39 AM
Obtaining source code for linux commands sreeramabsc Linux - General 10 01-29-2006 04:34 AM
can i access the source code of linux shell commands?? sharathg786 Red Hat 1 11-22-2005 06:08 AM
How to locate source code for external commands 2buck56 Linux - Software 4 04-15-2005 07:43 AM
Source code to commands uman Linux - Software 2 10-13-2004 12:07 AM


All times are GMT -5. The time now is 10:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration