•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 423,654 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,095 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 337 | Replies: 5 | Solved
![]() |
I am trying to create a simple C program that uses HandBrake (video converter). The only way to run this program is to have one of the (in my opinion) crappy GUIs or to type out all of the arguments in the command line. My program is simpler than the GUIs, and I don't need to type all of the arguments. I have everything ready except for one flaw. My program takes input that you want to be the file name after it is done converting. It saves the input in a variable named "filename". I then use system to run HandBrake and all of it's arguments. The code looks like this:
system("HandBrakeCLI -i /dev/hdc -o /root/??? -b 1024 -B 128 -R 48 -E faac -f mp4 -w 368 -l 208 -m");
Of course, the question marks aren't supposed to be there. That's where I'm stuck. I would like to have the input from the "filename" variable to be placed where the question marks are. I cannot use "$filename" because it shows an error while compiling. It might be something small that I missed, or I might just be doing it wrong. Any help is appreciated!
soppyhankins
system("HandBrakeCLI -i /dev/hdc -o /root/??? -b 1024 -B 128 -R 48 -E faac -f mp4 -w 368 -l 208 -m");
Of course, the question marks aren't supposed to be there. That's where I'm stuck. I would like to have the input from the "filename" variable to be placed where the question marks are. I cannot use "$filename" because it shows an error while compiling. It might be something small that I missed, or I might just be doing it wrong. Any help is appreciated!
soppyhankins
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,126
Reputation:
Rep Power: 38
Solved Threads: 929
declare a character array that is large enough to contain the filename and all the arguments, then pass that to the system() function. Example:
You may have to adjust the above if filename contains spaces.
char command[512] = {0};
char filename[255];
printf("Enter a file name\n");
fgets(filename,sizeof(filename),stdin);
// remove '\n'
filename[strlen(filename)-1] = 0;
sprintf(command,"HandBrakeCLI -i /dev/hdc -o /root/%s -b 1024 -B 128 -R 48 -E faac -f mp4 -w 368 -l 208 -m", filename);
system(command);You may have to adjust the above if filename contains spaces.
Last edited by Ancient Dragon : Aug 6th, 2008 at 11:42 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
•
•
// remove '\n' filename[strlen(filename)-1] = 0;
'\n' before destroying it. > I am trying to create a simple C program that uses HandBrake (video converter).
Is this a deliberate exercise in using C, or are you really just after a quick way of solving the problem, and you thought C might be the best answer?
Because if you're willing to entertain alternatives, then consider using the shell. Especially if all you're doing in your C program is a bit of string manipulation then calling system().
Note: the last line is all one line, ignore the forum line wrapping in code tags.
Is this a deliberate exercise in using C, or are you really just after a quick way of solving the problem, and you thought C might be the best answer?
Because if you're willing to entertain alternatives, then consider using the shell. Especially if all you're doing in your C program is a bit of string manipulation then calling system().
#!/bin/bash echo -n "What filename > " read filename HandBrakeCLI -i /dev/hdc -o /root/$filename -b 1024 -B 128 -R 48 -E faac -f mp4 -w 368 -l 208 -m
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 2
I suppose that you are using C language. Here is your function
c Syntax (Toggle Plain Text)
#include <stdlib.h> int RunSystemCmd(char *pfilename) { char buff[512] = {0}; if (pfilename == NULL) return -1; sprintf(buff,"HandBrakeCLI -i /dev/hdc -o /root/%s -b 1024 -B 128 -R 48 -E faac -f mp4 -w 368 -l 208 -m", pfilename); return system(buff); }
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Starting Python (Python)
- Open In New Window Php (PHP)
- New to Perl, please explain the script (Perl)
- "Forbidden / You don't have permission to access / on this server." error (Linux Servers and Apache)
- seek function (Perl)
- Global Variables not so 'global' (Visual Basic 4 / 5 / 6)
- file open code in VB (Visual Basic 4 / 5 / 6)
- This Should be Easy for You Guys! (Linux Servers and Apache)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
Other Threads in the C Forum
- Previous Thread: need help replacing characters
- Next Thread: Help with argc, argv



Linear Mode