Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening .txt file in execl()

Tags:

c

file

ubuntu

exec

How can I open a .txt file using execl() function? Is there any other function in c to open a file in gedit in Ubuntu.

Regards

like image 363
Alfred Avatar asked Jan 18 '26 06:01

Alfred


2 Answers

Is there any other function in c to open a file in gedit

Th easiest would be

system("gedit file.txt");

As a side-note you might want to look into xdg-open.

like image 120
cnicutar Avatar answered Jan 20 '26 23:01

cnicutar


You can try this also

execlp("/usr/bin/gedit","gedit","text.txt",NULL);

general syntax of execl() and execlp()

int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);

give full path of text.txt

like image 36
Omkant Avatar answered Jan 21 '26 00:01

Omkant