Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Calling External EXE

former_member194669
Active Contributor
0 Likes
1,553

Hi,

I have a requirement to call NOTEPAD.exe and call a TXT file from one local directory and save it in another local directory.

How to do this?

Thanks

aRs

15 REPLIES 15
Read only

Former Member
0 Likes
1,509

You have to create an external command in SM49 which calls notepad.exe . Then from the ABAP program, use function module SXPG_CALL_SYSTEM to invoke the command.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,509

If you would like to open a .txt file using notepad, all you need to do is this. Then you can save where ever.



call method cl_gui_frontend_services=>execute
   EXPORTING
     DOCUMENT               = 'c:file.txt'.

Is this what you want? Or do you want to save in another directory automatically?

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,509

If you simply want to copy the file without opening it, you can do this.



call method cl_gui_frontend_services=>file_copy
  exporting
    source             = 'C:file.txt'
    destination        = 'c:sapfile.txt'.

Regards,

Rich Heilman

Read only

former_member194669
Active Contributor
0 Likes
1,509

Hi Rich,

I need to save automatically to another directory, User interaction is not needed. and also i need not use FTP to move the file.

Thanks

aRs

Read only

0 Likes
1,509

Well, then you can use the FILE_COPY method of the class CL_GUI_FRONTEND_SERVICES. See the post above. It's that simple.

Regards,

Rich Heilman

Read only

0 Likes
1,509

I'm curious, what is the formatting that is happening when opening in notepad and saving?

Regards,

Rich Heilman

Read only

former_member194669
Active Contributor
0 Likes
1,509

Hi Rich,

Why i tried to use NOTEPAD.exe and save to another directory is of formating. Initially TXT files are not formatted by using NOTEPAD.exe and save i am getting proper formated text. But simply copying the files formatting not happended properly using "frontend->file_copy"

Thanks

aRs

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,509

What if you were to upload it and download it, would the formatting happen then?



report zrich_0001.

data: istr type table of string.
data: str_file type string.

parameters: p_file1 type localfile default 'C:file.txt'.
parameters: p_file2 type localfile default 'C:sapfile.txt'.

str_file = p_file1.

call method cl_gui_frontend_services=>gui_upload
  exporting
    filename                = str_file
  changing
    data_tab                = istr.

str_file = p_file2.

call method cl_gui_frontend_services=>gui_download
  exporting
    filename                = str_file
  changing
    data_tab                = istr.

Regards,

Rich Heilman

Read only

former_member194669
Active Contributor
0 Likes
1,509

Hi Rich,

We had a customised NOTEPAD.exe (written a new notepad.exe in Visual C++) that truncated the txt string to 132, and special characters get converted while saving.

Thanks

aRs

Read only

0 Likes
1,509

I see, so in other words, you must open notepad in order to have the formatting happen. So if that is the case, you can use the EXECUTE method that I mentioned above, but the user will need to save it to the directory. I don't think that you can manipulate Notepad via OLE programming.

Regards,

Rich Heilman

Read only

former_member194669
Active Contributor
0 Likes
1,509

Hi Rich,

I am looking for functionality like this

For example

DIR > T.TXT

Here t.txt have all dir entries

Is it possible same functionality if am calling this exe and results will go another file?

Thanks for your replies

ars

Read only

0 Likes
1,509

I don't follow.

Regards,

Rich Heilman

Read only

former_member194669
Active Contributor
0 Likes
1,509

Hi Rich,

If i am calling the EXE file like this.

appl = 'cmd'.

param = '/c YNOTEPAD.exe c:\test1.txt > c:\temp\test1.txt'.

call method cl_gui_frontend_services=>execute

exporting

application = appl

parameter = param

I tried like this way. but result not coming. Is anything i have to add to paramter statement here?

Thanks

aRs

Read only

former_member194669
Active Contributor
0 Likes
1,509

oops I misspelled the paramters while typing here

param = '/c YNOTEPAD.exe c:\test1.txt > c:\temp\test1.txt'.

I am giving like this way

param = 'c:\YNOTEPAD.exe c:\test1.txt > c:\temp\test1.txt'.

Thanks

Read only

0 Likes
1,509

If I understand correctly, you want to pass the contents of c:\text1.txt as input to c:\YNOTEPAD.exe and capture the formatted version into c:\temp\test1.txt.

It sounds like your YNOTEPAD program is still a text editor and that the formatting occurs on the save. The addition of "> c:\temp\test1.txt" is used to capture standard output. Unless the command line execution of "c:\ynotepad.exe c:\test1.txt" generates standard output, the "> c:\temp\test1.txt" addition won't work.