Is it okay to runtime exec external programs?

I have a need to get statistics from a couple network devices. They allow public snmp and I looked around for libraries to do snmpwalk but there is not very good ones out there (one costs money). I would like to copy the snmpwalk binary to my programs bin directory and execute it with the proper parameters, then read in the results. Then I will take the results and do what I need with them.
Is this generally frowned upon?

I reason that if I don't care for platform independent I use external programs.
For example if I know that my program will always run under Linux I use Linux internal programs.
Use http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html.

Similar Messages

  • SXPG_COMMAND_EXECUTE Can't exec external program (No such file or directory

    Hi Experts,
    I need to launch or terminate an external application (i.e. command prompt, notepad, etc.) in background job by using FM SXPG_COMMAND_EXECUTE. However, I am unable to proceed because of the following error occured after executing the command in SM69.
    Can't exec external program (No such file or directory)
    External program terminated with exit code 1
    I was using the following sample code. Can someone tell me what might be the cause of the problem?
    DATA: lv_status TYPE extcmdexex-status,
          lt_output TYPE TABLE OF btcxpm,
          lv_opsys  TYPE sy-opsys.
    lv_opsys = 'WINDOWS NT'.
    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
      EXPORTING
        commandname                   = 'ZIEXPLORE'
        additional_parameters         = '/c'
        operatingsystem               = lv_opsys
      IMPORTING
        status                        = lv_status
      TABLES
        exec_protocol                 = lt_output
      EXCEPTIONS
        no_permission                 = 1
        command_not_found             = 2
        parameters_too_long           = 3
        security_risk                 = 4
        wrong_check_call_interface    = 5
        program_start_error           = 6
        program_termination_error     = 7
        x_error                       = 8
        parameter_expected            = 9
        too_many_parameters           = 10
        illegal_command               = 11
        wrong_asynchronous_parameters = 12
        cant_enq_tbtco_entry          = 13
        jobcount_generation_error     = 14
        OTHERS                        = 15.
    ZIEXPLORE command
    Operating system command: cmd
    Parameters for operating system command: taskkill /f /im iexplore.exe
    Thanks and Regards,
    Louie

    Hi Louie,
    I am not able to assume the reason of the problem, If you say that its not getting executed in SM49 then the problem lies there.
    So I am providing you a link which might be helpful, just go through it and cross check. There is a parameter called "trace" in the fm mentioned.
    Secton Microsoft Windows NT - [Prerequisites for Running External Commands and External Programs|http://help.sap.com/saphelp_nw70/helpdata/en/c4/3a7fbb505211d189550000e829fbbd/content.htm]
    [Analyzing Problems with External Commands and Programs|http://help.sap.com/saphelp_nw70/helpdata/en/c4/3a80c4505211d189550000e829fbbd/content.htm]
    May be you can post this question in [SAP AS General|SAP NetWeaver Application Server; also.

  • SM69-Can't exec external program ( External program terminated with ecode1)

    Hi All,
    Client requirement is to Move File from Presentation Server to Application Server.
    I am executing UNIX script on AIX OS via SM69.
    But I am getting the  following error:
    Can't exec external program (No such file or directory)
    External program terminated with exit code 1
    Also getting same error with FM-SXPG_COMMAND_EXECUTE .
    Below is the code..
    data: l_exitcode type btcxpgexit,
            l_parms type btcxpgpar,
            l_status type btcxpgstat.
    data: lt_protocol type standard table of btcxpm,
            l_protocol type btcxpm.
    concatenate 'C:\Venkat1\PARBIND.BMP'
                          'D:\Venkat2\PARBIND.BMP'
                          into l_parms
                          separated by space.
    * External command:
    * - Unix - mv
    call function 'SXPG_COMMAND_EXECUTE'
      exporting
        commandname                   = 'Z_MV'
        additional_parameters         = l_parms
      importing
        status                        = l_status
        exitcode                      = l_exitcode
      tables
        exec_protocol                 = lt_protocol
      exceptions
        no_permission                 = 1
        command_not_found             = 2
        parameters_too_long           = 3
        security_risk                 = 4
        wrong_check_call_interface    = 5
        program_start_error           = 6
        program_termination_error     = 7
        x_error                       = 8
        parameter_expected            = 9
        too_many_parameters           = 10
        illegal_command               = 11
        wrong_asynchronous_parameters = 12
        cant_enq_tbtco_entry          = 13
        jobcount_generation_error     = 14
        others                        = 15.
    if sy-subrc ne 0
    endif.
    Can any one guide what is the cause of error....
    Any help will be appreciated.
    Regards
    Arbind

    Hi Paul,
    Thanks.
    But still Basis Consultants are telling it is correct from there side.
    Is there any other way to move files from Presentaion Server to Application Server in Background Processing.
    I have used CL_GUI_FRONTEND_SERVICES=>FILE_COPY
    It is working fine in Foreground but in Background Proceesing, it is not working.
    Can u provide any solution ?
    Thanks
    Arbind

  • SM69-Can't exec external program (Exec format error)

    Hi All,
    I am executing UNIX script on HP-UX system via SM69.
    But getting following error:
    u201CCan't exec external program (Exec format error)
    External program terminated with exit code 1u201D
    Also getting same error with FM-SXPG_COMMAND_EXECUTE & SXPG_COMMAND_EXECUTE
    Can any one guide what is the cause of error.
    Any help will be appreciated.
    Regards

    Check the Sample program. You can test or check the Unix commands using the below program.
    You can use the commands Like LS to list all the files.
    REPORT ZUNIX line-size 400
                    no standard page heading.
    data: unixcom like   rlgrap-filename.  
    "7 full perimission to read
    "7 full permission to change
    "7 full permission to delete
    unixcom = 'CHMOD 777 fillfullpath'.
    data: begin of tabl occurs 500,
            line(400),
          end of tabl.
    data: lines type i.
    start-of-selection.
      refresh tabl.
      call 'SYSTEM' id 'COMMAND' field unixcom
                    id 'TAB'     field tabl[].

  • Can't exec external program (Permission denied)-

    Hi All
    We have mentioned external command in SM69 and executed the command in SM49, I am getting the below error message.
    Command executed:      
    /home/ SMIME/run/signand.sh :
    Target host:            dt02
    Can't exec external program (Permission denied)
    External program terminated with exit code 1
    Program wise also I am unable to execute the command & I am getting sy-subrc eq 1. Please help me which authorization object is missing to run the external command.
    u_comm =  /home/ SMIME/run/signand.sh
      CALL 'SYSTEM'
      ID 'COMMAND' FIELD u_comm
      ID 'TAB'     FIELD rt-sys.
    Please confirm.

    Can you please check the permission for /home/ SMIME/run/signand.sh, perform below command
    chmod 755 /home/ SMIME/run/signand.sh
    and retry.

  • SM69 error-Can't exec external program (Permission denied).with exit code 1

    Hi All,
    I am trying to execute UNIX script via creating commend line in SM69.
    But i am getting following error:
    "Can't exec external program (Permission denied)
    External program terminated with exit code 1"
    Can any one guide me what could be the cause of this error.
    Any Help will be appreciated.
    Thanks & Regards

    First use SU53, to see if you have all SAP-authoritys.
    But I think, you have no authority to execute UNIX-programs.
    or your UNIX-script is not executable?

  • Runtime.exec() makes program act weird

    Hello
    I have a problem with the runtime.exec() command?
    I have created a program in vb.net with a tcpClient that opens a stream to a server.
    When i execute the program myself it works fine, but when i run it through my java applet with runtime.exec() its suddenly hangs reading the stream?
    I can't make it work, and its so weird that the program reads the stream several times and then just hangs, even though i can see in wireshark that packets are recieved.
    Please help anyone who might know how to solve this :)

    Read and implement the recommendations in all sections of [When Runtime.exec() won't|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html].
    db

  • Running the external programs from SM69 t-code and RSBDCOS0 report

    Hi All,
      I am trying to execute the external commands from SM69 and RSBDCOS0. It's throwing the below error:
    26.10.2009 17:26:49 Job started                                                                                00           516
    26.10.2009 17:26:50 Step 001 started                                                                                BT           611
    26.10.2009 17:26:50 External command: ZARCHIVELOG_COPY                                                                BT           630
    26.10.2009 17:26:50 Related parameter:                                                                                BT           613
    26.10.2009 17:26:50 Ext. prog.:   > Function: BtcXpgPanicCan't exec external program (No such file or directory)      BT      606
    26.10.2009 17:26:50 Ext. prog.: External program terminated with exit code 1                                          BT           606
    26.10.2009 17:26:50 Ext. prog.: SAPXPG started on <hostname>_<SID>_00, Process ID 1632, Process Number 12   BT           606
    26.10.2009 17:26:50 External program was cancelled                                                                    BT           614
    26.10.2009 17:26:50 Job cancelled                                                                                00           518
    <SID>adm has full authorization on sapxpg.
    Please let me know what might be the wrong.
    Regards,
    Sridhar

    Dear Markus,
       The dev_xpg file contains the below information
    Trace file of external program (trace level 3)
    < Function: BtcTrcInit> Function: BtcXpgStart  External program: mv
      Process id: 29450
      Parent process id: 29449
      Rearrange StdErr to be collected in memory
      Rearrange StdOut to be collected in memory
    In t-code sm21 dont have any thing.
    Regards,
    sridhar

  • Runtime.exec() and subprocesses

    I am running a bat file through Runtime.exec(). Conetent of bat file look
    likes following
    E:\Progra~1\Brio\SQRServer\ORA\BINW\sqrw d:/brio/par/par_pqa.sqr
    ibprod/active1@pscore -oC:/TEMP/sqr.log -printer:pd 88
    d:/Brio_Reports/report1.pdf d:/brio/
    exit
    Now this batch file starts another executable program. That program creates
    a report in a particular directory and exit the process. When I run this
    file from command prompt it runs fine. But if I try same thing from
    Runtime.exec(), my program hangs.
    From windows process monitor tools it seems that it start a new process but
    that process never ends. If I end that process forcefully then pointer
    again returns to my java program.
    any idea how to solve this problem.

    Is there maybe any stdout or stderr (console so to say) output which is not taken care of when the thing is called from Java?

  • Run external programs using runtime class

    Okay, I'm experiencing a really annoying problem with java.lang.runtime
    I'm building a GUI that needs to run some external programs, via a button say. These generally produce a text file or something, so I don't need to stream the output or anything (at least I'm assuming I don't?). Should be very simple...
    So at the terminal (bash) I would type ./programName , and everything will run hunkey dorey.
    In my code then, natrurally, I write
    String cmd = "./programName";
    Process p = runtime.getRuntime().exec(cmd);
    But low and behold...nothing happens. What is going on here, and how do I get around it! ??
    (On windows incidentally, it's no problem at all and works absolutely fine. But when I go over to mac, which is what I need to use, I'm screwed - only adding to the annoyance!)
    Any help would be much appreciated as I have a deadline looming!!

    You need to read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and implement the recommendations. Failure to implement all the recommendations will cause you grief.
    P.S. The fragment of code you have posted shows that you have fallen for at least 4 of the traps.

  • Trying to run external script using Runtime.exec

    Hey,
    I am trying to use Runtime.exec(cmd, evnp, dir) to execute a fortran program and get back its output, however it seems to always be hanging. Here is my code snippet :
                Process process = Runtime.getRuntime().exec(
                      "./fortranCodeName > inputFile.txt" , null, new File("/home/myRunDir/"));
                InputStream stream = new InputStream(process.getInputStream());
                InputStream error = new InputStreamr(process.getErrorStream());
                BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stream));
                BufferedReader erroutReader = new BufferedReader(new InputStreamReader(error));
                System.out.println(stream.available());  //returns 0
                System.out.println(error.available());     //returns 0
                while (true) {
                    String line1 = stdoutReader.readLine();  //hangs here
                    String line2 = erroutReader.readLine();
                    if (line1 == null) {
                        break;
                    System.out.println(line1);
                    System.out.println(line2);
                }I know for a fact that this fortran code prints out stuff when run it in terminal, but I don't know if I have even set up my Runtime.exec statement properly. I think I am clearing out my error and input streams with the whole reader.readLine bit I have above, but I am not sure. If you replace the command with something like "echo helloWorld" or "pwd", it prints out everything properly. I also am fairly confident that I have no environmental variables that are used in the fortran code, as I received it from another computer and haven't set up any in my bash profile.
    Any Ideas?

    Okay, so I implemented the changes from that website (thanks by the way for that link, it helps me understand this a little better). However, my problem is still occuring. Here is my new code:
                class StreamThread extends Thread {
                InputStream is;
                String type;
                StreamThread(InputStream is, String type)
                    this.is = is;
                    this.type = type;
                public void run()
                    try
                        InputStreamReader isr = new InputStreamReader(is); //never gets called
                        BufferedReader br = new BufferedReader(isr);
                        String line=null;
                        while ( (line = br.readLine()) != null)
                            System.out.println(type  +">"+  line);
                        } catch (IOException ioe)
                            ioe.printStackTrace();
            try {
                Process process = Runtime.getRuntime().exec(
                      "./fortranCodeName" , null, new File("/home/myRunDir/"));
                StreamThread stream = new StreamThread(process.getInputStream(), "OUTPUT");
                StreamThread errorStream = new StreamThread(process.getInputStream(), "ERROR");
                stream.start();
                errorStream.start();
                int exitVal = process.waitFor(); //hangs here
                System.out.println("ExitValue: " + exitVal);

  • Interact with extern process by Runtime.exec()

    Hi,
    I want interact with a extern process by Runtime.exec(), but I don't Know the way for introduce the params required for the extern process.
    So, Is posible, interact with the extern process from Java?
    Thanks

    Exactly, I would like to know how exec can pass a PIN
    number when the proccess already has been launched. Sounds like you're doing it through the process' stdin. Read that article I linked.
    You'll have to call Process.getOutputStream() or whatever that method is. To you it's an OutputStream, to the process, it's input. You'll write the stuff to that stream that you'd type to the command line. If you want to get that from the user interactively, you'll do it like you would any interactive user input in any Java program--get it by reading System.in or from some GUI element, and then take that and write it to the process' stream.
    If you're not familiar with I/O in Java, look here:
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Runtime.exec() - how to open new window for new program?

    Hi,
    I have searched through the forums but haven't found an answer to this one yet. I am using runtime.exec() to start up a new java program. At first I thought it wasn't running properly but, after checking task manager, I have discovered that the new program I open runs, it is just completely invisible to me. I am wondering how I can get the new program to run in a command window or something where I can monitor it.
    Thank you for your help,
    Drew

    Thank you all. After trying to figure out why the start command wouldn't work in the runtime.exec() call(not an executable - I am a dolt), I tried putting it in a batch file and it worked perfectly. Thanks for your help,
    Drew

  • System exec, How I say to open one file and make operation in external program?

    Hi,
    I got called an external program with the system exec.vi, but i would like the program open the file saved in the other window, i can get the file path, but how Can I put the file path in the external program and the program open the file and I tell (in this case compile), since i open one file code c and only i must to open and say to the program 'compile' and then close external program.
    Any help?. Thanks.
    Attachments:
    system_exec.GIF ‏8 KB

    Hi Fonsi,
    System Exec.vi will allow you to run commands like launching a program easily but it is difficult and many times not possible to execute commands within an application.
    A better way maybe to approach this though ActiveX. Please look at the following example that uses ActiveX to communicate with Excel.
    Writing Rows to Excel 97 and Excel 2000 Using ActiveX
    If you are not familiar to ActiveX and LabVIEW, please read the document below:
    ActiveX and LabVIEW
    I hope this
    helps.
    Sincerely,
    Feroz
    National Instruments

  • Runtime exec problem to execute a C program

    Hi,
    I've spend lot of time trying to find a solution without success...
    My aim is to run a C program from a java application under linux. My C code is the following:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    main(int argc, char **argv){
    printf("hello world \n");
    Once compiled I run my java application wich run the binary through a runtime.exec().
    I followed the example given by
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    with the same input gobblers and threads.
    For some reason it doesn't work: nothing comes out...
    When I call "ls" instead of my binary it works perfectly!
    WHY??
    Any help would be greatly appreciated!

    Thanks for the reply.
    Yes it seems that JNI could be a solution, but it looks a bit complicated an maybe not so well adapted to my purpose.
    The executables I want to execute from my java application don't need any arguments.
    If JNI is really the only way I'll try to use it but is there any good reason why runtime exec doesn't work? It is supposed to execute any executable isn't it?
    cheers

Maybe you are looking for

  • How do I find out if the pressed key is printable?

    I have made a game and now I'm working on a hiscore table for it. But with my function the program doesn't know if the pressed key is printable or if it's shift, ctrl or something like that. And I made it possible to enter maximum 40 letters as name,

  • Problem while Creating MVLOG with synonym in Oracle 9i:Is it an Oracle Bug?

    Hi All, I am facing a problem while Creating MVLOG with synonym in Oracle 9i but for 10G it is working fine. Is it an Oracle Bug? or i am missing something. SQL> select * from v$version; BANNER Oracle Database 10g Express Edition Release 10.2.0.1.0 -

  • My Apple TV is showing no signs of reconnecting a remote! Help!

    I cant get my 3rd generation Apple TV to connect to any of my remotes. I've tried restarting it & trying to reconnect the remote or remote app to the Apple TV but the TV shows no signs of a connection. Ive tried all the troubleshooting things for rec

  • Send multiple files in different directories using Receiver File Adapter

    Hi Experts, I have one File to File without ESR scenario where I have to pick multiple files from different directories and to save them in different directories on receiver side. Can anyne help me to send multiple files in different directories usin

  • InputVerifier for JComboBox

    Hi, I'm trying to set an InputVerifier for an editable JComboBox using the setInputVerifier() method, to check the input before the JComboBox looses the focus. I've tried several things, as for exmaple extending the 'BasicComboBoxEditor' and set the