encountered a command line argument to c program puzzle!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers encountered a command line argument to c program puzzle!
# 1  
Old 10-14-2011
encountered a command line argument to c program puzzle!

Hi,
I hope this is the right place to post this:
I have a cprogram written in openCV which reads a video file and does some processing: Here's a relevant code snippet:
Code:
//just in case you needed to know what libraries I included
#include<iostream>
#include<opencv/cv.h>
#include<opencv/highgui.h>
#include<dirent.h>
#include<string>
#include<cstdlib>
#include<cstdio>
#define SPACE_BAR 32
#define ENTER_KEY 10

using namespace std;
int main(int argc,char *argv[]){
        char title[]="ImageClipper";
        char title2[]="Cropped Image";
        if(argc!=2 && (cout<<"Usage: ./imageclipper <avi-path>"<<endl))exit(0);

        char *avifile=argv[1];
        cout<<"avi file is "<<avifile<<endl;

        CvCapture *capture=NULL;
 CvCapture *capture=NULL;
        capture=cvCreateFileCapture(avifile);
        if(capture==NULL){
          cout<<"capture is Null..exiting"<<endl;
          exit(1);
        }

// code to open some windows providing an interface to select sub regions of a frame...but the above lines should be sufficient
...
}

The problem faced:
When I run

Code:
./a.out path/to/video.avi

It works perfectly.

but when I run the following in a shell script(after creation of the txt file offline):
Code:
find path_to_folder_containing_avis -name "*.avi" > to_process.txt

for f in `cat to_process.txt`
do
./a.out $f
done

I get my error message "Capture is Null..exiting"(after the c++ program printed the right name). Any ideas why it's getting messed up?
# 2  
Old 10-17-2011
Try this instead of the for loop (eliminates useless use of cat). Use the echo line first to make sure the output is what you expect:
Code:
while read f
do
  ## echo $f
  ./a.out $f
done < to_process.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command line argument

Hi Guys, I'm trying to work out how to add a command line argument inside single quotes. Would anyone be able to help please as I'm going mad :) I want to be able to place the filename on command line and it then be used in a script but it needs to have quotes surrounding it. Thanks in... (4 Replies)
Discussion started by: mutley2202
4 Replies

2. Shell Programming and Scripting

Specify an entire UNIX command as a command line argument

I'm trying to write a bash script called YN that looks like the following YN "Specify a question" "doThis" "doThat" where "doThis" will be executed if the answer is "y", otherwise "doThat". For example YN "Do you want to list the file dog?" "ls -al dog" "" Here's my attempt... (3 Replies)
Discussion started by: LeoKSimon
3 Replies

3. Shell Programming and Scripting

Can a string be a command line argument?

I would like to use a string as a command line argument...is this possible using TCSH? For example say my script is called TEST and I would like to pass a string into my script stating why the test failed. EXAMPLE: TEST "Failed due to missing statement" (4 Replies)
Discussion started by: thibodc
4 Replies

4. Shell Programming and Scripting

command-line line 0: Missing yes/no argument

Hi Guys When I run the below command ssh -o 'PasswordAuthentication yes' -o 'PreferredAuthentications publickey' -i $HOME/.ssh/id_dsa Server_Name I found the below error ommand-line line 0: Missing yes/no argument Kindly help me to sort out Double post, continued... (0 Replies)
Discussion started by: Pratik4891
0 Replies

5. Shell Programming and Scripting

Need Help with the argument passing Through Command line

$$$$$ (5 Replies)
Discussion started by: asirohi
5 Replies

6. Programming

Command Line Argument

Hi, I have a very simple C program which will run in UNIX. When i am passing * as the command line argument, i am gettig the below output. Program: #include <stdio.h> #include "mylibrary.h" int **environ; int main(int argc,char *argv) { int i; printf("\nHello... (2 Replies)
Discussion started by: dsudipta
2 Replies

7. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

8. Shell Programming and Scripting

How to get the value in last command line argument???

Say I want to get the value of last command line argument using the value in $# (or some other way if u can suggest) how do I do it?? $"$#" `$"$#"` These don't work :( (4 Replies)
Discussion started by: amit_oddey21
4 Replies

9. Shell Programming and Scripting

passing a command line argument

I have a shell script which does the encryption of a file where i am passing the file name as a command line argument,but later on the script waits on the screen to enter Y or N what is the command i should be using on the shell script #!/bin/bash -x outfilename=file.out echo... (8 Replies)
Discussion started by: rudoraj
8 Replies

10. UNIX for Dummies Questions & Answers

command line argument parsing

how to parse the command line argument to look for '@' sign and the following with '.'. In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. rmjoe123@hotmail.com has '@' sign and followed by a '.' to be more... (1 Reply)
Discussion started by: rmjoe
1 Replies
Login or Register to Ask a Question