UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 21st, 2005, 09:29 AM
EverLearning EverLearning is offline
the ^ user
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: f(x)
Posts: 358 EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 46 m 31 sec
Reputation Power: 7
variables

Hello everybody,
I am executing a shell script from C++ program. However, the script has to be called multiple times with different names (from array), so names are variable. And I am not sure how to do this. Here is a relevant part of code:
Code:
 //File1, File2, are strings, array is array of strings
 File1 = Array[0];

 for (int i = 0; i < Index; i++)
 {
		
    File2 = Array[i++];
    File_Out = File1 + File2;
    i--; //get back to original pos;
		
   system("catwav File1.wav File2.wav File_Out.wav");  
		
   File1 = File_Out;

}

Boldfaced is the line where I need help: I think there should be a $ operator somewhere...

Thanks much.

Last edited by EverLearning : March 21st, 2005 at 09:38 AM.

Reply With Quote
  #2  
Old March 21st, 2005, 10:12 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
supply a buf
and sprintf in it
catwav File1.wav File2.wav File_Out.wav
before calling system
__________________
working on Solaris[5-9], preferred languages french and C.

Reply With Quote
  #3  
Old March 21st, 2005, 10:25 AM
EverLearning EverLearning is offline
the ^ user
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: f(x)
Posts: 358 EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 46 m 31 sec
Reputation Power: 7
Quote:
Originally Posted by guggach
supply a buf and sprintf in it
catwav File1.wav File2.wav File_Out.wav before calling system

Uuummm, you mean to do smth. like char buf[] for each?
Code:
char buf1[size] = File1.c_str();
char buf2[size] = File2.cstr();
char buf_out[size] = File_Out.c_str();

//and then just this?

system ("catwav buf1.wav buf2.wav buf_out.wav");

if not, then can you explain in greater detail?

<edit> that does not seem to work </edit>

Thanks a lot.

Last edited by EverLearning : March 21st, 2005 at 11:55 AM.

Reply With Quote
  #4  
Old March 21st, 2005, 03:53 PM
simscripts simscripts is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 simscripts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 26 sec
Reputation Power: 0
Can you tell me what is the exact type of File1 and File2 and File_Out?
If that are char * , then this
File_Out=File1+File2 would not work

Reply With Quote
  #5  
Old March 21st, 2005, 05:00 PM
EverLearning EverLearning is offline
the ^ user
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: f(x)
Posts: 358 EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 46 m 31 sec
Reputation Power: 7
Quote:
Originally Posted by simscripts
Can you tell me what is the exact type of File1 and File2 and File_Out?
If that are char * , then this
File_Out=File1+File2 would not work

What the script does is concatenates 2 wave files and saves it as a new wave file, i.e. last argument of the catwav (it works, I tried).
But what I need to do is create one big wave file out of an array of given names of existing wave files, for ex.
string array[size] = {"File1", "File2", "File3"}, i.e. there exist File1.wav, File2.wav, File3.wav;

I need to pass the names of the files as variables to the script: at first just first two and save it as File_Out.wav and then File1 = File_Out (just names, i.e. strings) and call the script again:
catwav File1.wav File3.wav File_Out.wav.

Only instead of using actual File1, etc. I need to use array[i].
I think the code I provided in the first post should take care of that, I just do not know how to implement variable use in shell scripts. If it were C I would not have a problem.

And yeah, I am using string type so for C++ so concatenation is done by "+".
Thanks for helping.

Last edited by EverLearning : March 21st, 2005 at 05:39 PM.

Reply With Quote
  #6  
Old March 21st, 2005, 09:05 PM
Andrew80's Avatar
Andrew80 Andrew80 is offline
Advanced Programmer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Malaysia
Posts: 437 Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 8 h 34 m 16 sec
Reputation Power: 32
Send a message via MSN to Andrew80 Send a message via Yahoo to Andrew80
you can do this
Code:
char * filename1 = "file1.wav";
char * filename2 = "file2.wav";

char buffer[80]; 

strcat(buffer,"catwav ");
strcat(buffer,filename1);
strcat(buffer,filename2);

system(buffer)


or , just use these functions

execl
execvp

or any othe function in that family .

Reply With Quote
  #7  
Old March 22nd, 2005, 02:59 AM
simscripts simscripts is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 simscripts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 26 sec
Reputation Power: 0
if you're using C++ style string variables then you could use another string variable that will hold the actual string that will go as the parameter for the system() function.
Code:
 buffer="catwav " +  File1 + " " + File2 + " " + File_Out;
 system(buffer.c_str());
 

Reply With Quote
  #8  
Old March 22nd, 2005, 10:44 AM
EverLearning EverLearning is offline
the ^ user
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: f(x)
Posts: 358 EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level)EverLearning User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 46 m 31 sec
Reputation Power: 7
Thanks everyone for help, it works!
I did not realize that system()'s argument can be manipulated as a regular string/char array.

Reply With Quote
  #9  
Old March 23rd, 2005, 03:02 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
Code:
char * filename1 = "file1.wav";
char * filename2 = "file2.wav";

char buffer[80]; 

strcat(buffer,"catwav ");
strcat(buffer,filename1);
strcat(buffer," ");
strcat(buffer,filename2);

a more elegant way:
sprintf(buffer,"catwav %s %s",filename1,filename2);

system(buffer)

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway