Thread: Small issue with system()

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    11

    Small issue with system()

    I have the following code
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    
    int main()
    {
    system("telnet site.com 80");
    system("GET /whatever.html HTTP/1.1");
    return 0;
    }
    It connects but I cant get it to execute the...
    Code:
    system("GET /whatever.html  HTTP/1.1");
    part of the code until I end my telnet session.

    So heres the questions, how do I make it connect and then send the GET request while it's still connected???

    I looked around the forums and google and i couldnt find anything that really anwsered my question, this thing has been driving me crazy for days.

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    The GET command is a part of FTP and Telnet. It is not a valid command on the command line.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    11
    I tried to put it in the same line
    Code:
    system("telnet site.com 80 GET /whatever.html HTTP/1.1");
    but that doesnt work either.

  4. #4
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    What I'm telling you is you cannot do that PERIOD. You cannot start telnet and then send in commands like that at all. Also I looked into it and I was wrong, Telnet does not have a GET command.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    254
    well you could try to open a pipe to telnet... or just learn some basic winsock...

    Telnet does not have a GET command.
    maybe not but when you are connected to a http server on port 80 and type that in something will happen!
    Last edited by ZerOrDie; 10-21-2003 at 10:16 AM.

  6. #6
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    maybe not but when you are connected to a http server on port 80 and type that in something will happen!
    The port is being opened with Telnet not an HTTP compliant program. Telnet is not the way to get files from a server for that purpose. Metal Man may wish to consider writing a mini web server that can do what it is he is looking to do instead.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    11
    i dont really care about the program displaying the html, i just want to send the GET command. I'm just trying to find a way to open the telnet session and then write to it.

  8. #8
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    With out a message loop like event driven programs have that might be difficult to do.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Seems to me that you need wget - or some other non-interactive browser like curl

    $ wget --help
    GNU Wget 1.8.2, a non-interactive network retriever.
    Usage: wget [OPTION]... [URL]...
    So
    system( "wget http://www.site.com/whatever.htm" );


    Or as ZerOrDie has hinted, use popen(), but that relies on knowing how to drive telnet PROPERLY, that is, use a telnet command which isn't GET

    Code:
    FILE *fp = popen( "telnet site.com 80" );
    fprintf( "get file\n" );  // needs some research
    pclose( fp );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  2. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  3. Small Logic Issue
    By Flakster in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2006, 02:40 PM
  4. Replies: 2
    Last Post: 03-19-2006, 09:32 AM
  5. Problem Reporting System. Need Advide!
    By brunomiranda in forum Tech Board
    Replies: 9
    Last Post: 09-25-2003, 09:21 PM