How  to execute os command from ABAP program?

I want to execute some window commands from ABAP. What is the way to do it?

Hi,
See ht e coding below, I have used these Fm to connect to FTP server and get the Files..
*types for the ftp command result internal table
TYPES : BEGIN OF ty_result,
        text TYPE char512,
        END OF ty_result.
data it_result type standard table of ty_result.
*Connect to the FTP server
  CALL FUNCTION 'FTP_CONNECT'
    EXPORTING
      user            = lv_user           " user name pass word to connect
      password        = l_v_pwd
      host            = 'dev.eu.pm.com' " Host name here
      rfc_destination = 'SAPFTPA'   "destination name
*Ask your functional people for the above data
    IMPORTING
      handle          = v_handle
    EXCEPTIONS
      not_connected   = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
  ENDIF.
*Changing directory
  CONCATENATE 'cd' '<file path>' INTO l_v_cmd SEPARATED BY space.
you can also ser 'DIR in l_v_cmd which opens the directory and all the folders *get into it_result table..
*Execute the FTP Command
  CALL FUNCTION 'FTP_COMMAND'
    EXPORTING
      handle        = v_handle
      command       = l_v_cmd
    TABLES
      data          = it_result
    EXCEPTIONS
      tcpip_error   = 1
      command_error = 2
      data_error    = 3
      OTHERS        = 4.
  IF sy-subrc <> 0.
  ENDIF.
rewards if useful,
regards,
nazeer

Similar Messages

  • How to execute system command from java program

    Hi all,
    I want to change directory path and then execute bash and other unix commands from a java program. When I execute them separately, it's working. Even in different try-catch block it's working but when I try to incorporate both of them in same try-catch block, I am not able to execute the commands. The change directory command works but it won't show me the effects of the bash and other commands.
    Suggestions??

    The code I am using is....
    try
    String str="cd D:\\Test";
    Process p=Runtime.getRuntime().exec("cmd /c cd
    "+str);your str string is already having cd in it but again you ar giving cd as part of this command also please check this,i will suggest you to remove cd from str
    Process p1=Runtime.getRuntime().exec("cmd /c mkdir
    "+str+"\\test_folder");you should say mkdir once you change your path,but here you are saying mkdir first and then cd D:\Test(this is because of str)..please check this
    Process p2=Runtime.getRuntime().exec("cmd /c bash");
    Process p3=Runtime.getRuntime().exec("cmd /c echo
    himanshu>name.txt");
    catch(IOException e)
    System.err.println("Error on exec() method");
    e.printStackTrace();
    Message was edited by:
    ragas

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to execute unix command from ODI Procedure

    Hi,
    I am trying to execute below unix command from ODI Procedure (Command on Target tab) but I am getting the error "java.io.IOException: Cannot run program "cd": error=2, No such file or directory" but when I try to execute the same command using OdiOSCommand, it is executing successfully. I don't want to use shell script to execute this command. Is there any specific syntax am I missing to execute this command from ODI procedure?
    cd /project3/tmt/;ls *.dmp > dmplist.lst
    Please help me on this...
    Thanks
    MT

    Hi nahlikh,
    Thank you for the reply.
    I used below command in Procedure but still getting the same error as "java.io.IOException: Cannot run program "OdiOSCommand": error=2, No such file or directory".
    OdiOSCommand "-COMMAND=cd /project3/tmt/;ls *.dmp > dmplist.lst"
    as I mentioned earlier if I use the command cd /project3/tmt/;ls *.dmp > dmplist.lst in OdiOSCommand tool it is executing successfully without any issues.
    any thoughts appreciated to get a solution for this issue.
    Thanks
    MT

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • Exec a "MV" (move) Linux command from ABAP program using wildcard "*"

    Hi,
    I have a problem by using FM "SXPG_COMMAND_EXECUTE", SM49 while i try to move the whole content of a SAP folder into another.
    Foders are on the same file system:
    source: /tmp/
    dest:   /usr/sap/tmp
    I made a command in SM69 named ZMOVE:
    I put OS: Linux (is case sensitive)
            command: "mv"
            parameters: /tmp/* /usr/sap/tmp
    hence the final sentence should be "mv /tmp/* /usr/sap/tmp". I did it directly by using program "rsbdcos0" and works fine.
    Now if I try to execute the command ZMOVE from SM49 or using the function module it gives the same error
    *mv: cannot stat  /tmp/ ': No such file or directory**
    I made several tries by changing the parameter section (also using a script on the same directory).
    The permissions are ok, so the only problem seems to be the wildcard (*) character.
    Any suggestions?
    Thanks in advance
    Fabrizio

    Problem solved.
    Forget function modules, SM69 etc. there's an ABAP command in order to perform a SO command.
    Here an example:
    data: lf_file like rlgrap-filename,
          lf_idx(3) type n,
          cmd(254),
          result(255) occurs 100 with header line.
    cmd = 'mv /dir_source/* /dir_dest'.
      call 'SYSTEM' id 'COMMAND' field cmd
                    id 'TAB'     field result-sys.

  • How to executing serial commands from text document

    I'm looking for some direction on how to read and execute a page of serial commands from a text file.  I have an instrument is controlled by serial communication.  Currently I have been using a state machine to operate the instrument.  The issue is that if I wish to change the sequence of commands I have to go back and rewrite the state machine to change the strings.  I had the idea of being able to just write the string commands to a text file with each line being a discrete command and after selecting the file the VI would execute the text page one line at a time.  I just don't  know where to start and have been unable to find an example to get me started.  This is above my programming level and I could use some direction on where to start.  The one issue I need to be able to address is if the VI executing the page of serial commands I have to have a way to abort the sequence if necessary.  
    Thank you
    Danny
    Danny

    ABCPrograms wrote:
    If you want to process the entire array of commands in a state engine, indeed the better way of keeping track of where you are in the array would be a shift register.
    When you're reading a new line, increase the index with one and put the new index in the shift register.
    That seems overly complicated, unless you want to go back and repeat steps.  But from the description from the OP, this is not desired.  The point of the text document is to easily change the state order.  Autoindexing is by far the simplest way to accomplish this.  If you really want to know what index you are on, just use the i terminal.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to execute Infopackage with an ABAP program

    Dear All,
    I would like to execute an infopackage every 6th day of the month.
    Therefore I would like to integrate a program in a process chain executed on a daily basis, and call with this program the execution of the infopackage if day = 6.
    Do you know how to execute an infopackage inside an ABAP program ? Which function module use ?
    Thanks,
    Greg

    Hello luminy13,
    Just to answer your question on how to start an InfoPackage inside an ABAP program: you can use function module BAPI_IPAK_START. You might also need to use FM BAPI_IPAK_CHANGE to change the scheduling.
    However, if the only reason you are creating the ABAP program is to run the InfoPackage at the 6th day of the month, then I don't recommend that you create the ABAP program at all. You can simply schedule the InfoPackage (or the process chain that contains it) on the 6th day of the month. Here's how to do it:
    In the scheduling dialog, click the ">>" button. Enter the factory calendar, put 6 is in the workday and then choose "beginning of the month".
    Hope this helps.

  • How to execute external command from SAP

    Hi gurus,
    i need to execute an external command from a Sap (rel ECC.5.0) to a server UNIX (no SAP); precisely i have to write a file into a directory in unix server.
    I see transaction SM49 and Sm69 but i don't know how can i use these features.
    Please coul'd you help me or give me a documentation.
    Thank's in advance
    Maurizio Ortolani
    email. [email protected]

    Hi Maurizio,
    i do it in this way:
    CONSTANTS: CMD_LS(50)   VALUE 'ls -al /transfer/sap'.
      DATA: BEGIN OF ITAB_LS OCCURS 0,
              LINE(200),
            END   OF ITAB_LS.
      CALL 'SYSTEM'
        ID 'COMMAND' FIELD CMD_LS
        ID 'TAB'     FIELD ITAB_LS-SYS.
    How do you write the file, via an UNIX-COMMAND than try the above call
    with your command.
    Another way is to write the file via OPEN DATASET ..., TRANSFER ... TO ..., CLOSE DATASET.
    If you mean this i can give you an example.
    Hope it helps.
    Regards, Dieter

  • Execute bsp application from abap program

    How can I do to execute a bsp application from abp program ?
    I have two parameter in enter : text and language.
    And i have one paramenter in exit : translated text.
    Thanks for you help.

    but how to retrieve the result of the bsp ?
    Here is my source code :
    data: url type string,
             l_appl type string,
            l_page type string,
            l_params type line of TIHTTPNVP,
            params type TIHTTPNVP.
      l_appl = 'ZAPI_TRADUCTION'.
      l_page = 'appel.htm'.
      l_params-NAME = 'text'.
      l_params-value = 'pour le moment test'.
      append l_params to params.
      call method cl_http_ext_webapp=>create_url_for_bsp_application
        exporting
          bsp_application      = l_appl
          bsp_start_page       = l_page
          bsp_start_parameters = params
        importing
          abs_url              = url.
    DATA: http_client TYPE REF TO if_http_client .
    DATA: w_string TYPE string ,
          w_result TYPE string ,
          r_str    TYPE string .
    DATA: result_tab TYPE TABLE OF string.
      CLEAR w_string .
      w_string = url.
      CALL METHOD cl_http_client=>create_by_url
        EXPORTING
          url                = w_string
        IMPORTING
          client             = http_client
        EXCEPTIONS
          argument_not_found = 1
          plugin_not_active  = 2
          internal_error     = 3
          OTHERS             = 4.
          CALL METHOD http_client->send
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2.
          CALL METHOD http_client->receive
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2
          http_processing_failed     = 3.
      CLEAR w_result .
      w_result = http_client->response->get_cdata( ).
      REFRESH result_tab .
    In the variable it brings me back the html source code of the BSP rather than run and bring me the result of the BPS.
    Thank you for your help.

  • Executing  InfoPackage Group from ABAP Program

    Hi Experts,
    I want to execute InfoPackage Group from the ABAP program. I know function module BAPI_IPAK_START which can schedule a single Infopackage at a time.
    Please let me know.
    Many Thanks,
    -Ashish

    Hi,
    I am using function module BP_EVENT_RAISE for raising a event.My question is which eventid I need to give in the export parameter.
    CALL FUNCTION 'BP_EVENT_RAISE'
      EXPORTING
        EVENTID                      = ' '
        EVENTPARM                    = ' '
    I need to mention some SAP standard event or I can create my own event too.
    Because same event I need to put in InfoPackage Group for scheduling.
    Regards,
    Ashish

  • How to trigger MDM Workflow  from ABAP Program.

    HI
    I have requriment  to trigger MDM Workflow(Design in MDM) from My Module pool program. Suggest how to do it?
    Thanks in Advance.
    Regards,
    Shyam Babu Sah.

    Hi,
    This question is for forum SAP Netweaver --> Workflow. There are functions and programmes that SAP delivers for this.
    [Example here|Re: How can I trigger workflow from my report]

  • How to connect to DB2 from ABAP program

    Hi,
    In my ABAP program I need to retrieve 3 fields from one table of DB2 database. I have tried creating an RFC connection in SM59 and then using native SQL in abap code but could not succeed.
    I have also maintained an entry in DBCON table but am unable to connect through program.
    Pls suggest.
    Thanx in advance.

    Preeti-
    DBCON may not work for you because your target is DB2. You SAP system should have the suitable driver files for connecting to DB2 and I don't think currently this is supported.
    However, there are other ways of doing it. One ofcourse is to use a middleware tool, which I guess you don't have in your landscape.
    If investing on a middleware tool is out of scope, here are other options
    1) If you are a microsoft shop, use .NET connector (freely downlaodable from SAP service market place). You can develop a .NET component which will use .NET connector for connecting to SAP and OBDC to connect to your AS400 system. The OBDC drivers can be obtained from IBM.
    2) If you are a java shop, you can develop a java code which can run on your AS400 system or a separte server (windows,unix..).
    This java code will use JRFC/JCO (again downloadable for free from SAP service market place) to connect to SAP while it will use Client access ODBC drivers or JT400 drivers (google JT400) to connect to your DB2 database.
    Though developing this is not a great deal, could be bit challenging if done for the first time. Let me know which way you wanna go and I can guide with more information/code samples.
    KK

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • How to execute .msi files from java program

    Hi friends,
    i have written a java program which invokes and thereby execute any executable files like .exe and .bat.
    So its working fine with .exe and .bat files, but it is not working with .msi files.......can you please help me how can i execute .msi files as well??
    public class Executeexe {
         public static void main(String ar[])
              try
              Process p=null;
              Runtime rt=Runtime.getRuntime();
              p=rt.exec("D:\\mysql-essential-5.0.83-win32.msi");
              p.waitFor();
    catch(Exception e)
    }here is the program

    Make sure that the command that's being exec'd works from the cmd line.
    Then read this article and do what it says:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Then if you still are having problems explain what "...it is not working with .msi files..." really means, and provide a [SSCCE Example program|http://mindprod.com/jgloss/sscce.html]

Maybe you are looking for

  • Preload External Jpgs

    What is the easiest way to preload external jpgs? The client wants to update these frequently so they should be external, but I want them to show up instantly like the rest of the site once the preloading is done. Any advice? I had thought about load

  • TRansfer Order - Negative stock figures

    Dear Friends: Using T.code LT03, I entered Warehouse no,plant,delivery and pressed enter In storage, I selected 003(open storage) and selected post In movement data, I entered the data source storage type: 003 (open storage) source storage section -

  • 8i password lost.

    Dear all, We have oracle 8i database. we dont have remember the system or sys password for dateabase . can you please tel me hove to change password of database. SRVMGRL is not working but SVRMGRL30 is working. how can i resolve this problem. Regards

  • OEM in 9i

    Hi friends, how can i access 9i's OEM from remote computer. Thanks

  • Oracle 9iAS administration tool with GUI??

    Hello, Has Oracle9iAS an administration tool with a GUI (web tool or similar...)?? I found some console commands to start/stop and deploy some EJB but it's too bored. If this tool exists, please tell me how can I access to it. Thanx in advance. Byeee