www.webdeveloper.com
Results 1 to 15 of 15

Thread: [RESOLVED] Cmd line app - check for running processes

  1. #1
    Join Date
    Jan 2009
    Posts
    31

    resolved [RESOLVED] Cmd line app - check for running processes

    Is anyone aware of a way I can get a list of the running windows process names?
    I'm not even sure how or if php can receive return data from a command-line application, so some pointers on that would also be helpful. I know of the tool pslist.exe, but that returns a lot of information.
    I'm checking for a few specific processes of which I know the processes names.

  2. #2
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    you can use
    PHP Code:
    $data shell_exec("pslist"); 
    and it will run the command and $data will have all the output
    you could use the string functions to go through all the data and find the stuff you want?

    Scott.
    Close the windows and get to know your inner Penguin with Linux

  3. #3
    Join Date
    Jan 2009
    Posts
    31
    I just attempted to use shell_exec() and to print the results, but nothing printed. Any ideas why?
    Edit: I just added or die, and it turns out the function failed.
    Last edited by khsater; 01-11-2009 at 10:00 PM.

  4. #4
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    who are you running pslist
    i am using xp pro and it is not there can u run it from command line on you server?
    by just typing pslist.exe in command line

    Scott.
    Close the windows and get to know your inner Penguin with Linux

  5. #5
    Join Date
    Jan 2009
    Posts
    31
    I'm running a program called wampserver. It's test software that basically works like a real server.
    Anyways, my server is local and pslist is 3rd party software but I put it in the system32 folder. I'm on x64 Vista.
    I ran the exe via exec() before, and that seemed to work fine.

  6. #6
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    i can't see any reason i dont know of any bugs with shell_exec and vista x64
    why not use exec then?
    like
    PHP Code:
    exec("pslist",$output);
    $output implode("\r\n",$output);
    echo 
    "<pre>"htmlspecialchars ($output)."</pre>"
    you should also be able to use the string functions to get special parts of the data and maybe make a array of running programs but could take a while to code

    Scott.
    Close the windows and get to know your inner Penguin with Linux

  7. #7
    Join Date
    Jan 2009
    Posts
    31
    It's strange, exec doesn't work any more either. Are there any php settings (besides safe mode) that might interfere with my using these functions?
    Oh, since Wamp is a virtual apache environment, system or exec calls apparently won't work. I guess I'll install php, then.
    Last edited by khsater; 01-11-2009 at 11:04 PM.

  8. #8
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    i have used xampp on my xp pro for a while it provides apache mysql and php on a almost normal install never had any problems and should have no problems accessing the command line

    Scott.
    Close the windows and get to know your inner Penguin with Linux

  9. #9
    Join Date
    Jan 2009
    Posts
    31
    Thanks a bunch for all your help and for that link. I was just trying to figure out what I could do to make this easier. I'll try it out in a bit and report back.

  10. #10
    Join Date
    Jan 2009
    Posts
    31
    Sorry about the double post, but for some reason I'm not allowed to edit my posts.
    It seems the problem is not solved with xampp as the application is still not being executed.
    Have you ever used exec() with xampp before?
    Edit: It seems that native commands work (I echoed pizza using exec and it returned pizza), but not my 3rd party app. Any ideas why?
    Last edited by khsater; 01-12-2009 at 03:13 PM.

  11. #11
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    i have only ever run normal windows commands but try specifying the full path like
    PHP Code:
    exec("C:\WINDOWS\system32\pslist.exe",$output); 
    might be a bit different for vista

    Scott.
    Close the windows and get to know your inner Penguin with Linux

  12. #12
    Join Date
    Jan 2009
    Posts
    31
    I did try running it using the full path.
    Perhaps it's some issue with Windows Vista security.
    It seems to just sit there waiting for a response from the server when I don't add the or die, though, which doesn't really make sense. There should be an error message from Windows if it's not working. I checked to see if the application was being run at all, using a task monitor, and the application is starting. There isn't a native windows command that returns running processes is there?

  13. #13
    Join Date
    Jan 2009
    Posts
    31
    Shoot. I meant that the application isn't starting.
    (That was a bad typo)

  14. #14
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    don't know if it is in vista but tasklist.exe works for me

    Scott.
    Close the windows and get to know your inner Penguin with Linux

  15. #15
    Join Date
    Jan 2009
    Posts
    31
    Thank you very much, Scott. That did the trick. It's still a mystery why I couldn't get pslist to work. I really appreciate the help.
    Now I just need to work out a good way to separate the array values into process names.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles