[c] How to call execl() in C with the proper arguments?

i have vlc (program to reproduce videos) if i type in a shell:

/home/vlc "/home/my movies/the movie i want to see.mkv"

it opens up an reproduces the movie.

however, when I run the following program:

#include <unistd.h>

int main(void) {

  execl("/home/vlc", "/home/my movies/the movie i want to see.mkv",NULL);

  return 0;
}

vlc opens up but doesn't reproduce anything. How can I solve this?

Things I tried:

I guessed

execl("/home/vlc", "/home/my movies/the movie i want to see.mkv",NULL);

was equivalent to typing in the shell:

/home/vlc /home/my movies/the movie i want to see.mkv

which doesn't work, so i tried

 execl("/home/vlc", "\"/home/my movies/the movie i want to see.mkv\"",NULL);

and vlc opens up but doesn't reproduce either.

Instead of writing NULL at the end I tried 0, (char*) 0, 1 .... not helpful. Help!!!!

This question is related to c exec external quotes unistd.h

The answer is


If you need just to execute your VLC playback process and only give control back to your application process when it is done and nothing more complex, then i suppose you can use just:

system("The same thing you type into console");


Examples related to c

conflicting types for 'outchar' Can't compile C program on a Mac after upgrade to Mojave Program to find largest and second largest number in array Prime numbers between 1 to 100 in C Programming Language In c, in bool, true == 1 and false == 0? How I can print to stderr in C? Visual Studio Code includePath "error: assignment to expression with array type error" when I assign a struct field (C) Compiling an application for use in highly radioactive environments How can you print multiple variables inside a string using printf?

Examples related to exec

I do not understand how execlp() works in Linux Running a Python script from PHP How do I execute a Shell built-in command with a C function? What are the uses of the exec command in shell scripts? php exec() is not executing the command How to call execl() in C with the proper arguments? Run Bash Command from PHP PHP shell_exec() vs exec() Ruby, Difference between exec, system and %x() or Backticks How to execute an external program from within Node.js?

Examples related to external

How to invoke function from external .c file in C? How to style SVG with external CSS? How to call execl() in C with the proper arguments? Android saving file to external storage Find location of a removable SD card PHP ini file_get_contents external url Getting the 'external' IP address in Java Eclipse: How to build an executable jar with external jar?

Examples related to quotes

YAML: Do I need quotes for strings in YAML? Regex to split a CSV Expansion of variables inside single quotes in a command in Bash How to call execl() in C with the proper arguments? Insert text with single quotes in PostgreSQL When to use single quotes, double quotes, and backticks in MySQL Difference between single and double quotes in Bash Remove quotes from a character vector in R How do I remove quotes from a string? How can I escape a double quote inside double quotes?

Examples related to unistd.h

Cannot open include file: 'unistd.h': No such file or directory How to call execl() in C with the proper arguments? Is there a replacement for unistd.h for Windows (Visual C)?