ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Actually I have difficulty phrasing what my problem is, but i'm trying to be as descriptive as possible.
I am doing a program in C and right now I can call lynx to execute in the program that I made, by using a fork() and execvp(). Is there a programming solution so that emulated typing the options on lynx? To illustrate what I mean, here's what an example of what I want to happen:
if I am actually using lynx and I want to print the page I am viewing to a file, I press P for the printing options, and then select the print to file option, and then I enter the filename. Can a make a program that does this so that the following sequence of options can be fed to lynx from my C program? I would greatly appreciate any help. Thanks in advance.
Hi,
what you want to do is to search for the command line options of lynx to achieve what you want. I think that any of the features you have can be used in the command line.
What you want to do it is teoricaly possible, but I am not sure how to do it. And it is too ofuscated for my taste (the first solution is much more elegant).
What I mean is that I want a certain webpage to be saved using lynx without the user manually entering the commands on how to save the text or html file of a certain webpage, as viewed in lynx. Is there a way to feed the sequence of commands to lynx by an external program, and how can I do it? It is assumed that the user is not familiar with lynx and does not have the time to learn using it. It is like automatically feeding the necessary commands to lynx without the user doing it all, the user just needs to select a certain option from the program that I made. I hope this clears out what I wanted to happen. I really need some suggestions on how to do this. I'd be really greatful in any help that can be given to me.
And reading the above guide I notice there was -cmd_script option that reads a file a sequence of commands (letters) and executes them the way you wanted before. Weird, but its a built in function hehe
And reading the above guide I notice there was -cmd_script option that reads a file a sequence of commands (letters) and executes them the way you wanted before. Weird, but its a built in function hehe
Cheers!
I really have to read this, and I really appreciate your help.
where "file://localhost/root/code_cpy/error.html" refers to my url or to a local html file,
whatI get is the display of the my html document on the screen
which is just like typing on the terminal window the following:
Is there anyone who would be able to help me out save the dumped contents into the file? I thought I would be able to figure out once I knew how it is done in lynx, since I can use the execlp function, but I have but it seems that I have problems with the arguments ">" and "filename". Can someone enlighten me about the problem?
You need to set up the file descipters for stdout using dup2 before calling exec.
Code:
int fd = open("sample1.txt", O_WRONLY);
dup2(fd, STDOUT_FILENO);
execlp(...);
I have problems with the O_WRONLY variable, the compiler says that the variable is undefined. I think I am lacking header files. I have already included termios.h, stdio.h, unistd.h and sys/types.h. Have I forgotten some other header files? I am not familiar with most of the header files in Linux. Thank you so much for the help. I hope this fixes my problem.
try including fcntl.h, as stated on the man page. You can also pull a file descripter out of a FILE*, but make sure everything is synced up right.
i've already tried including fcntl.h, but it did not work. i have read somewhere that the open() function works only in dos, so i tried using an alternative, creat() and it seemed to compile, but nothing was written to the text file that i created, the code is:
Code:
int fd;
fd = creat("sample1.txt",S_IWRITE|S_IREAD);
dup2(fd, STDOUT_FILENO);
execlp("lynx","lynx","-dump","file://localhost/root/code_cpy/error.html",">","/root/sample1.txt", NULL);
Would have been good to know you're trying to do Windows programming. Lots of stuff doesn't work quite as you would expect, and you have to do the nasty fix below a lot.
fcntl.h is still what you want, but you have to do
Code:
#ifdef _MSCVER
#define _open open
#define _O_WRONLY O_WRONLY
#endif
If you are merely trying to copy webpages/sites, the definitive tool for the purpose would be wget. More flexible, and made specifically for the purpose. You can specify an output file as a commandline argument (via execlp(...) ), and the whole business can be concealed from your users, if you wish to run it that way. I think there are Windows binary packages of wget, but it should be quite portable should you need to build it yourself.
Would have been good to know you're trying to do Windows programming. Lots of stuff doesn't work quite as you would expect, and you have to do the nasty fix below a lot.
fcntl.h is still what you want, but you have to do
Code:
#ifdef _MSCVER
#define _open open
#define _O_WRONLY O_WRONLY
#endif
Blech, not-quite-POSIX-ness of Windows.
Did I forgot to mention that I am doing my program in linux? Sorry about that. I hope I can find a fix to this.
If you are merely trying to copy webpages/sites, the definitive tool for the purpose would be wget. More flexible, and made specifically for the purpose. You can specify an output file as a commandline argument (via execlp(...) ), and the whole business can be concealed from your users, if you wish to run it that way. I think there are Windows binary packages of wget, but it should be quite portable should you need to build it yourself.
--- rod.
Thanks for the suggestion, what I really wanted is the stripped off version of the webpages/sites, the way it is displayed on lynx, without the html formatting, yet I will be able to distinguish which ones have hyperlinks to other sites, and with the intention of using the program in Linux.
Sure. You do understand that the output of lynx will be littered with screen formatting escape codes that are used to position the text on the screen, create colors, create underlines, and various other formatting? I would think that it would be easier to get rid of the HTML formatting, but that's just me, perhaps.
Here's a sample, formatted with od:
Code:
0000000 esc [ ? 1 0 4 9 h esc [ 1 ; 5 0 r esc
0000020 [ m esc ( B esc [ 4 l esc [ ? 7 h esc [
0000040 ? 1 h esc = esc [ 3 9 ; 4 9 m esc [ 3
0000060 9 ; 4 9 m esc [ m esc ( B esc [ H esc [
0000100 2 J esc [ 4 8 d esc [ 0 ; 1 m esc ( B
0000120 esc [ 3 3 m esc [ 4 4 m G e t t i n
0000140 g sp h t t p : / / s 0 1 0 6 0 0
0000160 4 0 f 4 8 4 0 1 8 a . v f . s h
0000200 a w c a b l e . n e t / c g i -
0000220 b i n / h i t S o u r c e s . p
0000240 l esc [ 3 9 ; 4 9 m esc [ m esc ( B cr
0000260 esc [ 0 ; 1 m esc ( B esc [ 3 3 m esc [
0000300 4 4 m L o o k i n g sp u p sp s 0
0000320 1 0 6 0 0 4 0 f 4 8 4 0 1 8 a .
0000340 v f . s h a w c a b l e . n e t
0000360 esc [ 3 9 ; 4 9 m esc [ m esc ( B esc [
0000400 K cr esc [ 0 ; 1 m esc ( B esc [ 3 3 m
0000420 esc [ 4 4 m M a k i n g sp H T T esc
0000440 [ 1 5 @ P sp c o n n e c t i o n
0000460 sp t o esc [ 4 8 ; 6 1 H esc [ 3 9 ;
0000500 4 9 m esc [ m esc ( B cr esc [ 0 ; 1 m
0000520 esc ( B esc [ 3 3 m esc [ 4 4 m S e n
0000540 d i n g sp H T T P sp r e q u e s
0000560 t . esc [ 3 9 ; 4 9 m esc [ m esc ( B
0000600 esc [ K cr esc [ 0 ; 1 m esc ( B esc [ 3
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.