Linux equivalent to Win32 ShellExecute

This is a discussion on Linux equivalent to Win32 ShellExecute within the Linux Programming forums, part of the Platform Specific Boards category; Is there a Linux equivalent to the following Win32 statement? Code: ShellExecute(NULL, "open", "http://myplace.com/forum/myforum",NULL, NULL,SW_SHOWNORMAL); It displays a web page ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059

    Linux equivalent to Win32 ShellExecute

    Is there a Linux equivalent to the following Win32 statement?

    Code:
          ShellExecute(NULL, "open", "http://myplace.com/forum/myforum",NULL, NULL,SW_SHOWNORMAL);
    It displays a web page from within an app

    Thanx

  2. #2
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Hi

    Maybe this will be useful for you, if you just want to display a web page with a browser. Or, you can use the same way I used, to call any function.
    Code:
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    
    int foo(char *adr[])
    {
            pid_t pid;
    
            pid=fork();
            if (pid==0)
            {
                    if (execv("/usr/bin/mozilla",adr)<0)
                            return -1;
                    else
                            return 1;
            }
            else if(pid>0)
                    return 2;
            else
                    return 0;
    }
    
    int main(int argc,char *argv[])
    {
            if (foo(argv)<=0)
                    perror("foo");
            return 0;
    }
    Run the program from command line by passing the address of the page you want to display.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Your example is exactly what I need.

    Thanx!

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    And what if mozilla suite isn't installed? How can I open a page in the default browser?

  5. #5
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Just change the code for your favorite browser! You can make a search in the PATH to locate any possible browsers (mozilla, firefox, konqueror...)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  2. Linux equivalent to CreateDirectory
    By Rak'kar in forum Linux Programming
    Replies: 2
    Last Post: 07-10-2004, 12:04 PM
  3. How to compile it under linux and win32
    By GaPe in forum C Programming
    Replies: 4
    Last Post: 12-28-2002, 01:44 PM
  4. Linux for Windows!
    By Strut in forum Linux Programming
    Replies: 2
    Last Post: 12-25-2002, 10:36 AM
  5. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 08:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21