|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
Quote:
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. |
|
#6
|
||||
|
||||
|
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 . |
|
#7
|
|||
|
|||
|
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()); |
|
#8
|
|||
|
|||
|
Thanks everyone for help, it works!
I did not realize that system()'s argument can be manipulated as a regular string/char array. |
|
#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) |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|