0

How to create command line application c++ or Java? I have some commands which I would like to convert into an application.
How to do it in eclipse?
Just for example consider:

sudo apt-get upgrade xyz

I want to get it into ubuntu repository. Or I'll create a gui using qt with c++ or java plugin.

4
  • 1
    What do you mean by an "application"? If you have a command, it's already an application. Do you mean to ask how you package it up for distribution? How to get it into the Ubuntu repos?
    – Kevin
    Aug 17, 2013 at 14:52
  • 3
    I think he is trying to make a package that can be added to a PPA and updated/modified and upgraded via apt-get. But in it's current form this question is too vague to answer...
    – Thomas Ward
    Aug 17, 2013 at 14:59
  • Are you looking for ways to creating a command line application? Please be more specific about exactly what you want so we can satisfactorily answer your question.
    – jokerdino
    Aug 18, 2013 at 5:16
  • This appears to be two questions: one asking how to make an application that runs commands, and another asking what the different options are for making programs available to Ubuntu users. If that is the case, I recommend removing the second question (by editing), changing the title to reflect just the first one, searching for answers to the second question, and posting the second question as a separate question if you don't find answers. Aug 18, 2013 at 7:50

2 Answers 2

2

In C++ you can use int system (const char* command); function.

Example:

/* system example : DIR */
#include <stdio.h>      /* printf */
#include <stdlib.h>     /* system, NULL, EXIT_FAILURE */

int main ()
{
  int i;
  printf ("Checking if processor is available...");
  if (system(NULL)) puts ("Ok");
    else exit (EXIT_FAILURE);
  printf ("Executing command DIR...\n");
  i=system ("dir");
  printf ("The value returned was: %d.\n",i);
  return 0;
}

Source: http://www.cplusplus.com/reference/cstdlib/system/

In your case you can use:

system ("sudo apt-get upgrade");

In Java is slightly more complicated. You can use exec method of the Runtime class in java.lang. See http://www.linuxforums.org/forum/programming-scripting/65117-c-c-system-function-analog-java.html

0

If you want to be able to use the apt-get command with your programm, it needs to be in a apt repository, whose url must be in the /etc/apt/sources.list file. You can learn how to set up your own apt repository here.

0

Not the answer you're looking for? Browse other questions tagged .