LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 03: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, 03:41 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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, 03: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, 04:03 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

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


Reply



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 09:30 AM
script for executing a program and doing string comparison b-neva Programming 9 05-07-2009 03:52 PM
Run an external script, without holding up the currently executing script onesikgypo Programming 2 03-07-2009 09:26 PM
Executing a program in c daYz Programming 2 07-27-2007 03:34 PM
Executing a program on start up andrewthk Debian 3 03-23-2006 12:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:49 PM.

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
Open Source Consulting | Domain Registration