HI, I need to know how to write a make file in linux to do the following task: run a java program (using the command java add 10) a given number of times and write some of the output variables (say x,y,z) to a file. I am a novice, so a sample makefile would really help. Thanks
Why a makefile? They are not suited to the task that you propose. Make does not pass command line arguments to tasks, so you would not be able to specify how many times you wanted to run the task. Make is designed to build files when another file it depends on changes. The only way I see this working is if you had some number in one file, say in.txt and you always wanted the number in some othe file, say out.txt to be 10 greater. In that case you might set up a makefile like this: ([tab] means a tab character goes there) out.txt: in.txt [tab]cat in.txt | java add 10 > out.txt Any time that in.txt changed, you could type make and out.txt would be updated. To add in the number of times that you wanted this to execute, I would think that have to write a wrapper script. Make has no concepts of loops or branches. [ November 05, 2002: Message edited by: Steve Deadsea ]
posted 17 years ago
Hi, You are right, what I actually need is the script file to do the above task. thanks,
Basically if you can do these things at the command line then you can do them in a batch file. You would write a file that has the lines you need to execute, for example if the line you need to do to run your program is: java add 10 then you just type that line into a file (let's call it "myfile"). If you wanted to route the output of that program to a file you use the standard unix re-direct commands of > or >> java add 10 > output.txt When you have written this list of commands you then set your file to be "executable" Look at the Unix command chmod to see how to do this. In any Unix or Linux system you can get that information via the man pages like this: man chmod But if you just want to make the file executable for the user who wrote it you would do this: chmod myfile u+x Once you've set the file to be executable you run it like this: ./myfile The ./ means "run the file of this name in THIS directory rather than searching for it in my path" That should be enough to get you started.
For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
I simplified it a bit to make it generic, but this does illustrate that for those times that the builds will look similar, but may need special environment settings, a Makefile is as good as anything. If you really need to pass command line parms, then a script file is probably the answer. (My own preference is Perl, of course!) If the project is way more complex, you may want to take a look into the Jakarta Ant project. For building my multi-class projects, I prefer to use the facilities of a good IDE, like Netbeans. PCS [ November 05, 2002: Message edited by: Philip Shanks ]
Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!