Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Writing Binary Front ends? (C++)

    I'm new to programming in Linux- you can kinda say I'm new to programming in general.
    I have only had experience in Uniy3D with C# - a little experience in Silverlight and then I went on to a little WP7 silverlight.
    I have studied but not learnt C/C++ when I was about 12/13- I'm 17 now so would like to put it to some good use.

    The problem is, I'm always focused to much on flying and doing barrel rolls, before I have even learn't to walk. I have studied ASM and kernel development - it's what I did through my school life - Every waking moment I was studying kernel development - learning about IA_32 instruction set and reading documentation all based around that.
    Because of all this studying I have a strong theory based background , but it's wasted with the lack of programming knowledge I have.

    Thats my story over with. I guess my current goal is to learn how to walk.
    I want to write a simple GUI front end to the update-grub and grub-install application's.

    I have become educated about the system() call but I can't find any information on handling any output from the calls them self.
    I don't know if system() is the best function to use.

    How would I go about inputing , calling , gathering and analyzing data from the terminal?

    This little project will also get me more in tune with the MVC model - it sure hell is more understandable then the Model View View-Model model...

    Anyway, thanks for any replies. I appreciate your time.

  2. #2
    system() gives you no direct way to read what the command it runs prints to stdout/stder. You can get this with popen(), but you're limited to only reading or writing (not both) and you can't read stderr.

    The best way I found to do this was to use a mixture of fork(), exec(), pipe() and dup() - look up the man pages if you're not familiar. Here's some code I wrote a while ago; put it on my blog because it comes up every now and again, and like I said it was a while ago, I may want to tidy it up and comment it better etc. It compiles and runs though. It's at cat /dev/thoughts: Running a program and interacting with it.. Feel free to ask any further questions about how it works, here or on the blog.
    Programming and other random guff: cat /dev/thoughts > (previously

  3. #3
    I might be able to offer some cool thoughts too. But I don't entirely understand the nature of update-grub and grub-install. They are command line applications, right? And you'd just like to 'skin' them and allow mouse presses to control the programs instead of a list of presumably somewhat complicated arguments? If that's the case (and you'd like to learn MVC) then maybe Sinatra would be an enjoyable place to start.

    Sinatra is based on the Ruby language, which is often referred to as a 'glue language' because it's often used to glue other pieces of code together in a quick snappy, reliable and easy to test manor.

    Basically, to create the UI, you create a web page that is able to execute commands on the local machine.

    (setup the machine so you can test out ruby programming)
    $  apt-get install ruby1.9.1
    #  sinatra, the framework you'll be using is packaged as a ruby 'gem' so install it
    $  gem install sinatra
    require 'sinatra'
    #require 'pry'
    get '/' do
          <h1>Welcome to grub-installer UI!</h1>
          <a href="/perform_action">Perform Operation On System!</a>
    get '/perform_action' do
      result = `echo 'CMD LINE OPERATION!' >> ~/sinatra_outputs`
      last_exit_code = $?.exitstatus
      if last_exit_code == 0
        "The Operation Was Performed... last_exit_code:  #{last_exit_code}"
        "Something went a bit wrong and echo didn't return an exit code of zero... #{last_exit_code}"
    In my example, we aren't using MVC exactly because we haven't split our html up into html file, CSS file and of course javascript. Web apps are a really good idea if you've already picked up an understanding of html just from browsing around the web.

    Oh, run the application by starting the server and then opening a web browser and pointing it to the local host at the appropriate port (localhost:4567).
    $  ruby hello_sinatra.rb

  4. $spacer_open

Posting Permissions

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