GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Mar-2004, 20:25
nuwandee nuwandee is offline
New Member
 
Join Date: Feb 2004
Posts: 4
nuwandee is on a distinguished road
Unhappy

Call a C program through Linux shell script


Hi all,
I have a bit strange issue. I have a shell script that fetch some information to shell variables and calls a C program with those shell variable.(14 variables passed).
However when this executes I miss one or two parameter values in the C program. (but not all). When I printf the values one by one argv[x] displays all the values. However even this If I use the following it prints with some missing Charaters.
printf("1:%s \n",argv[1]);
printf("2:%s \n",argv[2]);
printf("3:%s \n",argv[3]);
printf("4:%s \n",argv[4]);
printf("5:%s \n",argv[5]);
printf("6:%s \n",argv[6]);
printf("7:%s \n",argv[7]);
printf("8:%s \n",argv[8]);
printf("9:%s \n",argv[9]);

the output looks like this.

1:abcde
:abcde@domain.lk
:192.168.1.249
4:2004-2-29 22:05:46
:abcde@yahoo.com
6:0
7:0
:test-xp-01
9:email.content
0:1
11:0
12:0
13:1
14:email.envelope

With missing printf characters. 2,3,5,8 and character 1 of 10 is missing.
After I assign the parameter to C variables with strcpy() and the printf returns the following.

1:abcde
2:
:192.168.1.249
4:2004-2-29 22:05:46
:abcde@yahoo.com
6:0
7:0
:test-xp-01
9:email.content
0:1
11:0
12:0
13:1
14:email.envelope

Here I am using Bash shell on a Redhat 9.0. I tried with different version but the results same. However when I call the C program directly it outputs correctly. The problem exists only with Shell script and C integration.
I tried gcc versions gcc version 2.96 and gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7).

Please help me. I am stuck. Sorry for the long description. Thanks
  #2  
Old 29-Mar-2004, 20:46
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,648
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Post the program and the shell script.

here's my shellscript (I've used '\' so that the listing won't be too wide to see here).
My program name is "shelltest".

Quote:
#!/bin/sh
./shelltest abcde abcde@domain.lk 192.168.1.249\
"2004-2-29 22:05:46" abcde@yahoo.com 0 0\
test-xp-01 email.content 1 0 0 1 email.envelope


Does your program process this OK? If so, what's your shell script look like?
If not, what's your program look like?

Dave
  #3  
Old 29-Mar-2004, 21:46
nuwandee nuwandee is offline
New Member
 
Join Date: Feb 2004
Posts: 4
nuwandee is on a distinguished road
Unhappy

Quote:
Originally Posted by davekw7x
Post the program and the shell script.

here's my shellscript (I've used '\' so that the listing won't be too wide to see here).
My program name is "shelltest".




Does your program process this OK? If so, what's your shell script look like?
If not, what's your program look like?

Dave

############################
Thanks for the reply. Yes Of cause it process fine when I call the C program through Shellscript with real values as you did. But if I replace those values with shell variable the problem occurs.
  #4  
Old 29-Mar-2004, 21:54
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,648
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by nuwandee
############################
Thanks for the reply. Yes Of cause it process fine when I call the C program through Shellscript with real values as you did. But if I replace those values with shell variable the problem occurs.

Well, maybe someone can help you, but I can't magically see what you are trying to do. Sorry.

Dave
 
 

Recent GIDBlogA Week in Kuwait by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozilla Thunderbird dsmith Computer Software Forum - Linux 9 01-Mar-2005 11:56
Changing monitors on a Linux machine JdS Computer Software Forum - Linux 10 23-Dec-2004 09:49
Linux Kernel Upgrade Mini Howto dsmith Computer Software Forum - Linux 3 05-Apr-2004 22:10
JavaScript Tutorial Part 1 pcxgamer Web Design Forum 2 01-Dec-2003 09:16

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.