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.

2 Answers2

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

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
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.