Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-16-2008, 12:07 PM   #1
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


#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]); 
 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";

 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.


Last edited by cyberfox007; 01-16-2008 at 12:09 PM.
Old 01-16-2008, 03:11 PM   #2
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.


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 04:39 AM
Obtaining source code for linux commands sreeramabsc Linux - General 10 01-29-2006 03:34 AM
can i access the source code of linux shell commands?? sharathg786 Red Hat 1 11-22-2005 05:08 AM
How to locate source code for external commands 2buck56 Linux - Software 4 04-15-2005 06:43 AM
Source code to commands uman Linux - Software 2 10-12-2004 11:07 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:27 PM.

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