Sponsored Content
Full Discussion: C++ and Unix NEED HELP
Top Forums UNIX for Dummies Questions & Answers C++ and Unix NEED HELP Post 302645537 by KUJayhawk123 on Wednesday 23rd of May 2012 04:30:05 PM
Old 05-23-2012
C++ and Unix NEED HELP

In order to run some procedures I have to run multiple unix codes which are all programs written in the computer. For example:
: ../../bin/takeData -l -dir ../../Working_Directory -trimVcal 60
then after that is ran I'd have to run
: cd ../convert_to_tree
: ./convert_to_tree XXXX
: ./pulseHeightMain XXXX
: cd ~/log/bt0500XXXX
etc.
the XXXX represents a test run number. What I want to do is be able to type a program that would look like this:
: ./AquireData -dir Working_Directory -run XXXX
that would run all above and more. AquireData would be the C++ file. What I have so far is:

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(int argc, char* argv[]) {

string file_name;
string run_num;
string config_file;
int opt = 0;

for (int i = 1; i < argc; i++) {
           if (i + 1 != argc)
               if (argv[i] == "-dir") {
                   file_name = argv[i + 1];
               } else if (argv[i] == "-run") {
                   run_num = argv[i + 1];
               } else if (argv[i] == "-mask") {
                   opt = 1;
               } else if (argv[i] == "-cfg") {
                   config file = argv[i+1];
               }
           std::cout << argv[i] << " ";
       }

if (opt == 0){
// Unix commands for unmasked
}

if (opt == 1){
// Unix commands for unmasked
}

return 0;
}

Here is my two main questions:
1. When I'm in the directory what would I type with the arguments to compile and run the c++ code and read the argument line? and can I make it look like how I wanted to above?

2. How to I put unix commands in c++ so I could have something like:
cd ~/log/bt0500 << run_num

Note: I haven't used C++ in awhile so some of the easy stuff has slipped past me, but also the reason I'm using c++ is because a shell command script like AquireData.C wouldn't be able to input directory, run number, and other options, or would it?

Last edited by Corona688; 05-23-2012 at 05:42 PM..
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX problem? Unix programm runs windows 2000 CPU over 100%

Okee problems...!! What is happening: Unix server with some programms, workstations are windows 2000, the workstations work good but when you start a programm on the Unix server the CPU of the workstations go to 100% usage resulting that the system gets very slow. The programm well its running so... (2 Replies)
Discussion started by: zerocool
2 Replies

2. UNIX for Dummies Questions & Answers

Unix History Question: Why are filenames/dirnames case sentsitive in Unix?

I tried looking for the answer online and came up with only a few semi-answers as to why file and directory names are case sensitive in Unix. Right off the bat, I'll say this doesn't bother me. But I run into tons of Windows and OpenVMS admins in my day job who go batty when they have to deal... (3 Replies)
Discussion started by: deckard
3 Replies

3. UNIX for Advanced & Expert Users

missing Path(in UNIX) when i launch a job on to unix machine using windows SSh

hi i want run an unix application from a windows program/application.i am using SSH(command line version)to log on to a unix machine from windows. the application has to read a configuration file inorder to run. the configuration file .CFG is in bin in my home directory. but the application... (1 Reply)
Discussion started by: megastar
1 Replies

4. Shell Programming and Scripting

FTP script for sending a file from one unix directory to another unix server director

Hi, My local server is :/usr/abcd/ Remote server is :/Usr/host/test/ I want to send files from local unix directory(All files starting with O_999) to remote host unix directory. Can any body give me the Unix Shell script to do this. One more doubt: Shall we need to change the file... (1 Reply)
Discussion started by: raja_1234
1 Replies

5. Shell Programming and Scripting

Batch job in unix server to move the pdf file from unix to windows.

Hi Experts, I have a requirement where i need to setup a batch job which runs everymonth and move the pdf files from unix server to windows servers. Could some body provide the inputs for this. and also please provide the inputs on how to map the network dirve in the unix like that... (1 Reply)
Discussion started by: ger199901
1 Replies

6. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

7. Shell Programming and Scripting

File Transfer from Window server to UNIX and UNIX to UNIX

Dear All, Can someone help to command or program to transfer the file from windows to Unix server and from one unix server to another Unix server in secure way. I would request no samba client. (4 Replies)
Discussion started by: yadavricky
4 Replies

8. Post Here to Contact Site Administrators and Moderators

VIP Membership - The UNIX and Linux Forums - Get Your UNIX.COM Email Address Here

We work hard to make The UNIX and Linux Forums one of the best UNIX and Linux knowledge sources on the net. The site is certainly one of the top UNIX and Linux Q&A sites on the web. In order to provide certain members the best quality account services, you can now get some great extra features by... (2 Replies)
Discussion started by: Neo
2 Replies
SMRSH(8)						      System Manager's Manual							  SMRSH(8)

NAME
smrsh - restricted shell for sendmail SYNOPSIS
smrsh -c command DESCRIPTION
The smrsh program is intended as a replacement for sh for use in the ``prog'' mailer in sendmail(8) configuration files. It sharply limits the commands that can be run using the ``|program'' syntax of sendmail in order to improve the over all security of your system. Briefly, even if a ``bad guy'' can get sendmail to run a program without going through an alias or forward file, smrsh limits the set of programs that he or she can execute. Briefly, smrsh limits programs to be in a single directory, by default /usr/libexec/sm.bin, allowing the system administrator to choose the set of acceptable commands, and to the shell builtin commands ``exec'', ``exit'', and ``echo''. It also rejects any commands with the characters ``', `<', `>', `;', `$', `(', `)', ` ' (carriage return), or ` ' (newline) on the command line to prevent ``end run'' attacks. It allows ``||'' and ``&&'' to enable commands like: ``"|exec /usr/local/bin/filter || exit 75"'' Initial pathnames on programs are stripped, so forwarding to ``/usr/bin/vacation'', ``/home/server/mydir/bin/vacation'', and ``vacation'' all actually forward to ``/usr/libexec/sm.bin/vacation''. System administrators should be conservative about populating the sm.bin directory. For example, a reasonable additions is vacation(1), and the like. No matter how brow-beaten you may be, never include any shell or shell-like program (such as perl(1)) in the sm.bin direc- tory. Note that this does not restrict the use of shell or perl scripts in the sm.bin directory (using the ``#!'' syntax); it simply dis- allows execution of arbitrary programs. Also, including mail filtering programs such as procmail(1) is a very bad idea. procmail(1) allows users to run arbitrary programs in their procmailrc(5). COMPILATION
Compilation should be trivial on most systems. You may need to use -DSMRSH_PATH="path" to adjust the default search path (defaults to ``/bin:/usr/bin'') and/or -DSMRSH_CMDDIR="dir" to change the default program directory (defaults to ``/usr/libexec/sm.bin''). FILES
/usr/adm/sm.bin - default directory for restricted programs on most OSs /var/adm/sm.bin - directory for restricted programs on HP UX and Solaris /usr/libexec/sm.bin - directory for restricted programs on FreeBSD (>= 3.3) and DragonFly BSD SEE ALSO
sendmail(8) $Date: 2013-11-22 20:52:00 $ SMRSH(8)
All times are GMT -4. The time now is 02:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy