Visit Our UNIX and Linux User Community


how to pass input from c program to shell script?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to pass input from c program to shell script?
# 1  
Old 01-31-2012
Question how to pass input from c program to shell script?

Hello..
I am developing a Graphical User Interface using GTK. As part of our project I need to take inputs from GTK entries and pass those inputs to shell script and use them in shell script. The problem which struck me is only limited number of inputs are getting passed to shell script. For now only 15 characters are being accepted. I think there is a problme in passing the inputs from gtk program to shell script.
I used the following code to link up gtk program and shell script

void dadd(GtkWidget *widget, gpointer label)
{
char str[512];
int x;
sprintf(str,"sh st1.sh %s",charadd1);
x=system(str);

}

Here "st1.sh" is the shell script to which he inputs have to be passed and in charadd1 the values entered in gui entry filed will be stored. I also tried increasing the size of str bt it dint work.
# 2  
Old 01-31-2012
give a try..

Code:
sprintf(str,"\"sh st1.sh %s\"",charadd1);

---------- Post updated at 09:36 AM ---------- Previous update was at 09:33 AM ----------

or you can read about the popen function

popen function
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 01-31-2012
Thank you for your reply.. ok.. I'l try it.. but what is the meaning of the changes which you suggested?
# 4  
Old 01-31-2012
If you quote the arguments, then you can easily read the big string as $1 inside the shell script.

Code:
 
$ cat test.sh
echo $1
$ ./test.sh ABC CDE FGG
ABC
$ ./test.sh "ABC CDE FGG"
ABC CDE FGG

# 5  
Old 01-31-2012
Sory it's not working.. It's returning the error "command not found"
# 6  
Old 01-31-2012
show your code

---------- Post updated at 10:11 AM ---------- Previous update was at 10:10 AM ----------

before executing the system function, print and verify what str has

Code:
 
printf ("%s\n",str);
x=system(str);

# 7  
Old 01-31-2012
Ok I will.. Can I mail you the code?
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #714
Difficulty: Medium
Machine learning is a well known method for mitigating the Von Neumann performance bottleneck
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How pass the input parameter to a file in the script ?

OS version: RHEL 6.7 myTextFile.txt file is referred within Script1.sh script, I only execute Script1.sh and I want the input variable to be passed inside myTextFile.txt . Any idea how I can do this ? $ cat script1.sh cat myTextFile.txt $ cat myTextFile.txt $1 Requirement1.... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Shell Programming and Scripting

Read input from file and pass it to sub shell

i have a scenario where in i have to monitor jobs which run in different servers, The job details(job name, host server, etc) are present in a dat file. I have written a script a script which reads the details from the dat file and calls a local method where the job monitoring logic is present.... (2 Replies)
Discussion started by: abubucker0
2 Replies

3. Shell Programming and Scripting

Seeing input that you redirect to a program on the shell

Suppose I have a program that I've written that accepts input, ie this C++ program: #include <iostream> using namespace std; int main() { cout << "Enter something:" << endl; int x; cin >> x; cout << "You entered data" << endl; } Suppose that I have a text file,... (5 Replies)
Discussion started by: Chris J
5 Replies

4. Shell Programming and Scripting

Write a shell program with input

Hi, Here is my question: I want a shell script which I name as 'del', and can be used as del(string). when run del(string), it will delete several directories at different locations in my system,like: rm -fr /lustre/fs/scratch/user/$string rm -fr /home/user/$string rm -fr... (4 Replies)
Discussion started by: 1988PF
4 Replies

5. Shell Programming and Scripting

Shell script to input as if from command line to the java program

Hi, We are having a java server which can run on command line and once initiated, it will prompt options to enter from 0 to 5. The java program kickoff respective operation once number is entered between 0 to 5. However i want to always enter "1" and write another shell program wrapper to start... (4 Replies)
Discussion started by: surya5kn
4 Replies

6. Shell Programming and Scripting

Call java program from shell and pass values

Hi All, Can anybody please help me with how can i call my java program from shell and also pass parameter along with it so that the program can interpret the value/int and update the database. Thanks in advance Neha (1 Reply)
Discussion started by: Neha Goyal
1 Replies

7. Shell Programming and Scripting

Launching a C program that needs input from a shell script

hi there, i need some help, i am trying to run a script to launch a C program and a Java program but before running both I want to get a user input and then invoke both programs with input received. In the programs the inputs are not command line arguments. This is the code, after the java... (4 Replies)
Discussion started by: momal
4 Replies

8. Shell Programming and Scripting

Can we pass an array of strings from a Perl Program to a Shell Script?

Hi Folks, The subject is my question: Can we pass an array of strings from a Perl Program to a Shell Script? Please provide some sample code. Thanks ---------- Post updated at 11:52 PM ---------- Previous update was at 11:43 PM ---------- I got it. Its here:... (0 Replies)
Discussion started by: som.nitk
0 Replies

9. Programming

How to pass C array as input to Shell script

Hi, In the below C code , i want to pass the array to a unix shel script. my script should called as ex myscript 1,2,3 #include <stdio.h> int main() { int a={1,2,3}; } Thanks, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

10. Shell Programming and Scripting

pass the input to invoking script

How to pass the input to the execution script ex: test1.sh contains #! usr/bin/sh read val echo $val test2.sh contains #! /usr/bin/sh ./test1.sh now I am calling test2.sh thro command line and I want to pass the input to the script test1.sh from test2.sh ..I mean not... (6 Replies)
Discussion started by: vastare
6 Replies

Featured Tech Videos