[c++] shell opdrachten

Pagina: 1
Acties:

  • elgringo
  • Registratie: Januari 2001
  • Laatst online: 22-04 08:47
Ik heb een C++ programma onder linux die vanuit een commandline een java programma moeten runnen die wat analyses doet.

Ik wilde dit eerst met JVM doet, maar ik denk dat het lastig gaat worden. Daarom ben ik maar naar andere opties op zoek.

Het C++ programma heeft een file van een plaatje (met een niet standaard bestandsnaam) tot zijn beschikking. Deze file staat in een willekeurige directory. Vervolgens moet het Java programma aangeroepen worden die wat analyse doet mbt dit plaatje:

i.e. javaproggie -opties -m macro plaatje.ext

Deze regel wil ik dus door C++ laten uitvoeren. Is dit mogelijk?

if broken it is, fix it you should


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 21-04 01:08

.oisyn

Moderator Devschuur®

Demotivational Speaker

Ja, staat in de documentatie (hint: system())

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Lethalis
  • Registratie: April 2002
  • Niet online
.oisyn schreef op maandag 28 november 2005 @ 11:53:
Ja, staat in de documentatie (hint: system())
Dat is voor de blocking call. Ik weet niet of de TS het asynchroon wil doen? :X

In dat geval moet hij kijken naar popen() en waitpid() :)

Ask yourself if you are happy and then you cease to be.


  • moto-moi
  • Registratie: Juli 2001
  • Laatst online: 09-06-2011

moto-moi

Ja, ik haat jou ook :w

Waarom wil je dat met c++ oplossen :?
Waarom niet gewoon een shellbestandje a la

code:
1
2
3
#!/bin/bash
javaproggie -opties -m macro $1
exit 0

God, root, what is difference? | Talga Vassternich | IBM zuigt


  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 09-04 22:08
Ik gok omdat de TS meer in z'n C++ deel doet dan Java starten. Tenslotte zou hij ook alles in Java kunnen doen, dan is dat bash ook niet nodig.

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein


  • Zoijar
  • Registratie: September 2001
  • Niet online

Zoijar

Because he doesn't row...

Dit een voorbeeld hoe je een child process kan debuggen/staren:

C:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
int main(int argc, char* argv[], char* envp[]) {
   pid_t child_pid;
   int status;
   struct cmd_conf cmd_line;
   struct prof_data profdata;

   if (process_commandline(argc, argv, &cmd_line) < 0) {
      fprintf(stderr, "usage: %s [-n number_of_rows] [-r startaddr-endaddr] program-name [program_arguments ...]\n", argv[0]); 
      exit(1);
   }

   if ((child_pid = fork()) != 0) {
      /* Wait for the profiled process to start.
       * We have to do this to make sure the childs execv has completed
       */
      waitpid(child_pid, &status, 0);

      /* If the childs execv failed, we must exit too */
      if (WIFEXITED(status)) {
         fprintf(stderr, "%s: Failed to execute program '%s'\n", argv[0], cmd_line.program);
         exit(1);
      }

      /* Start profiling the child process */
      if (profile(child_pid, cmd_line.start_addr, cmd_line.end_addr) < 0) {
         /* On error kill the child before it ever runs */
         ptrace(T_EXIT, child_pid, 0, 0);
         fprintf(stderr, "%s: profile() failed. (%d)\n", argv[0], errno);
         exit(1);
      }

      /* Resume/start child until it terminates */
      do {
         ptrace(T_RESUME, child_pid, 0, 0);
         waitpid(child_pid, &status, 0);
      } while (!(WIFEXITED(status) || WIFSIGNALED(status)));

      /* Stop profiling */
      profile(0, 0, 0);

      /* Get profiling data, and display it */
      if (getprof(&profdata) < 0) {
         fprintf(stderr, "%s: getprof() failed. (%d)\n", argv[0], errno);
         exit(1);
      }

      display_profiling_data(&profdata, &cmd_line);

   } else {
      /* Inform the mm this process wants to be traced by its parent */
      ptrace(T_OK, 0, 0, 0);

      /* Execute the program to be profiled */
      execve(cmd_line.program, cmd_line.arguments, envp);

      /* If execv returns there must have been an error, so exit */
      exit(1);
   }
   return 0;
}

  • elgringo
  • Registratie: Januari 2001
  • Laatst online: 22-04 08:47
moto-moi schreef op maandag 28 november 2005 @ 12:32:
Waarom wil je dat met c++ oplossen :?
Waarom niet gewoon een shellbestandje a la

code:
1
2
3
#!/bin/bash
javaproggie -opties -m macro $1
exit 0
Ik heb dus een programma in C++ (gui, drivers) en een Java proggie die wat analyse moet verrichten op een plaatje

if broken it is, fix it you should


  • elgringo
  • Registratie: Januari 2001
  • Laatst online: 22-04 08:47
Ik wil iets ala system() maar dan dat het een thread wordt.

Ik dacht het te kunnen doen dmv een dubbel fork maar dit wordt me iets te complex omdat ie ook onder QT hangt. Verder klan ik de socket++ classes tegen, maar deze geven foutmeldingen die ik in kan plaatsen (undefined reference to `ipipestream::ipipestream[in-charge](char const*)).

Wat kan ik nog meer proberen?

if broken it is, fix it you should

Pagina: 1