Using C to call other programs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    Using C to call other programs

    I have a java class exe.class I would like to call this program using c.
    I tried the following methods none of them seems to work if you know where the problem is please help.
    Code:
    main(){[INDENT]System("java C:/Users/sthato/workspace/NumThe/bin/exe");[/INDENT][INDENT]execlp("java","C:/Users/sthato/workspace/NumThe/bin/exe");[/INDENT][INDENT]execlp("C:/Program Files/Java/jdk1.6.0_07/bin/java.exe","C:/Users/sthato/workspace/NumThe/bin/exe");[/INDENT]
    When I run
    Code:
    java C:/Users/sthato/workspace/NumThe/bin/exe
    from command prompt it works.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by thatos
    I have a java class exe.class I would like to call this program using c.
    I tried the following methods none of them seems to work if you know where the problem is please help.
    Code:
    main(){[INDENT]System("java C:/Users/sthato/workspace/NumThe/bin/exe");[/INDENT][INDENT]execlp("java","C:/Users/sthato/workspace/NumThe/bin/exe");[/INDENT][INDENT]execlp("C:/Program Files/Java/jdk1.6.0_07/bin/java.exe","C:/Users/sthato/workspace/NumThe/bin/exe");[/INDENT]
    When I run
    Code:
    java C:/Users/sthato/workspace/NumThe/bin/exe
    from command prompt it works.
    The name of your class is exe.class, not C:/some/path/to/your/exe.class. Try to use the classpath parameter, i.e:

    Code:
    system("java -cp C:/Users/sthato/worksapce/NumThe/bin exe");
    kind regards,

    Jos

    Comment

    • thatos
      New Member
      • Aug 2007
      • 105

      #3
      Thanks to Josh

      I tried that line of code and it works, thank you.

      Comment

      Working...