简体   繁体   中英

How to work in batch mode

I have inherited an ANSI C++ program that: has no GUIs and is supposed to run in batch mode, generating lots of data (we are talking 100,000+ ASCII files). We are thinking that in long term we'll run it under UNIX. For now, I have a MacBook Air running OS X 10.9.4 and I loaded Xcode 5.1.1. It compiles without errors or warnings.

I need to test a program as follows:

<prompt> myprogram datain dataout1 datout2

Where is the compiled program? In which directory? Can I copy my datain file in that directory?

For repeated execution under Windows (Command Prompt window) I normally would have a batch file of the type:

myprogram datain1 dataout11 datout12
myprogram datain2 dataout21 datout22
myprogram datain3 dataout31 datout32
........
myprogram datainn dataoutn1 datoutn2

Can I do something similar with OS X? Where can I find the applicable documentation?

You will want to look for your terminal emulation program. See http://en.wikipedia.org/wiki/Terminal_(OS_X) for how to use it, and it should be the bash shell which is one of the unix shells

You can also do a shell script see http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html for some bash shell scripting info

For such a simple operation, you can write a shell script that will look almost exactly the same as the batch file you use on Windows. The key difference between Windows' cmd.exe and *nix shells here is that the current directory is not part of the search path for executables (the way it is on Windows), so if you put the shell script in the same folder as the compiled executable, you will need to prefix the program name with ./ (to mean "look in the current directory"). For example:

#!/bin/sh
./myprogram datain1 dataout11 datout12
./myprogram datain2 dataout21 datout22
./myprogram datain3 dataout31 datout32
........
./myprogram datainn dataoutn1 datoutn2

If the shell script and executable are not in the same folder, you can use either an absolute path or an appropriate relative path.

Also, to run the script you will either need to make it executable:

$ chmod +x myscript.sh
$ ./myscript.sh

or invoke the shell with the script as an argument:

$ sh myscript.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM