LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-12-2014, 04:32 PM   #1
raetters
LQ Newbie
 
Registered: May 2014
Posts: 2

Rep: Reputation: Disabled
Executing a C program from a script


I currently execute a C program (example: /bin/cprogram) from a command prompt including passing a 600 character string within double quotes, and an output file name (example: /usr/outputfile).

Example:

$ /bin/cprogram "very long string with spaces, special characters, but no double quotes, etc etc" /usr/outputfile

Question: How would I write a shell script to receive that 600 character string and the output file name as input variables and then execute that same C program?
 
Old 05-12-2014, 04:41 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
I would suggest changing the cprogram to read from stdin.

That way the "600 character string" could be from a file, or a pipe...

Much more flexible.

But a shell script has exactly the same format as the command.
 
Old 05-12-2014, 04:51 PM   #3
raetters
LQ Newbie
 
Registered: May 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
This is what I've tried without success:

#!/bin/sh
read input
read filename

/bin/cprogram $input $filename

I include the double quotes on my input. Would that be lost somewhere?
 
Old 05-12-2014, 05:03 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,358

Rep: Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990Reputation: 1990
Yes, that would be lost where you use $input, put quotes around that
Code:
/bin/cprogram "$input" "$filename"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
executing perl script inside shell script scriptme101 Programming 3 04-11-2012 10:30 AM
script for executing a program and doing string comparison b-neva Programming 9 05-07-2009 04:52 PM
Run an external script, without holding up the currently executing script onesikgypo Programming 2 03-07-2009 10:26 PM
Executing a program in c daYz Programming 2 07-27-2007 04:34 PM
Executing a program on start up andrewthk Debian 3 03-23-2006 01:49 AM


All times are GMT -5. The time now is 02:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration