cancel
Showing results for 
Search instead for 
Did you mean: 

External command to execute Batch file in Windows REMOTE desktop

UmaArjunan
Active Participant
0 Kudos

we have to execute a external command from SAP server to trigger a batch file placed in remote desktop.

Our basis consultant successfully created a RFC TCP\IP connection in SM59 by the standalone gateway in the remote desktop.

setup

SAP server running in Linux OS

Batch file placed in Windows OS as a Remote Desktop.

Now the question is how to frame the external command in SM69 to trigger the batch file in the windows machine by using the RFC connection ?

As we tried external commands is runnnig at OS level accepting only Linux commands

if we give a directory path as the external command and executing using the RFC connection it is always failing ... do we need to enable anything or write windows compatible shell command . Please suggest if this is workable ..

Jelena
Active Contributor
0 Kudos

Why do you need this? What is this mysterious batch file on a remote PC supposed to do? Why must it be triggered from the SAP server?

Sorry but this kind of "architecture" sounds like something from the 80s. And not in a good way. If you can explain the end goal perhaps an alternative solution could be suggested.

raghug
Active Contributor
0 Kudos

Jelena, are you calling me old 🙂 ... I beg to differ about the 80's - through most of the 90's it was still the most reliable way to connect to SAP "real-time"

Jelena
Active Contributor
0 Kudos

OK, let it be 90s. It's ancient times either way. 🙂

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

To connect the external command to an RFC proceed as follows:

1. Create an RFC (Type T) with the following options:

a. Program: sapxpg

b.Target Host: <your remote OS (e.g. IP)>

c. Gateway Host: <your remote OS (e.g. IP)>

d. Gateway service: <the gateway service of the installed SAP Gateway on the remote host>

2. Create the external command in SM69/SM49 ==> Press Save and Press Execute ==> You will see another screen where you can specify the target destination (Target Dest.), created at point 1 ==> Execute the command in Dialog or create a Background job.

raghug
Active Contributor
0 Kudos

I remember doing things like this many years ago... here is a little brain dump of what I remember...

1) The program being executed on the remote system needs to implement an RFC connection back to SAP in order to let SAP know the call was successful

2) The program could work without #1 above, but SAP wouldn't know

3) The permissions to execute the program on the remote system were always tricky to setup - If everything else looked ok, I would bet this is your problem

4) I think Matthew's WSDL idea would be easier to manage in the long run.

UmaArjunan
Active Participant
0 Kudos

thanks for the reply. If you could recollect provide the #1 steps . RFC connection created using the option Start on expicit host. this solution is half the way, sap is running under Unix OS and the external created to execute batch file in remote desktop is not working, sm21 log shows unable to execute the external command

raghug
Active Contributor
0 Kudos

Sorry, it's been close to 20 years ago that I was involved with that. What I do remember was that we had a program written in C++ that established the connection back to SAP. Check out this document, maybe it will help https://assets.cdn.sap.com/sapcom/docs/2016/09/faa21fe1-8a7c-0010-82c7-eda71af511fa.pdf

Also do a Google Search for "SAP RFC SDK" or "SAP NW RFC SDK", you should get information about newer ways of connecting to SAP that I believe are much easier to use than the old methods.

UmaArjunan
Active Participant
0 Kudos

Thanks matthew and Robert, In my case Windows machine is a remote desktop and we installed stand alone gateway for communication. Is this sufficient to create a webservice ? I will create a webservice with the help document and get back

Meanwhile trying to understand what is the issue in the windows connect RFC connection, Can it not support to execute external commands or in other words just wanted to try that option if there is any workaround available as we already tried with this approach.

matt
Active Contributor
0 Kudos

"In my case Windows machine is a remote desktop and we installed stand alone gateway for communication. Is this sufficient to create a webservice ?"

I think you need to ask this on a windows OS support site.

UmaArjunan
Active Participant
0 Kudos

posted in Microsoft support site.. waiting for the answer

matt
Active Contributor
0 Kudos

For a similar scenario, we created a web service on the windows server, that could be consumed from an ABAP program. The webservice ran a batch file with supplied parameters.

UmaArjunan
Active Participant
0 Kudos

Could you please elaborate with the steps ?

matt
Active Contributor
0 Kudos

Sure. Create a web service on windows that runs your batch job with supplied parameters. You can use C++, C#, Java or whole host of languages for this. Make sure that the web service starts when the service starts. From this web service, get the WSDL file. (This is all standard stuff that anyone who develops on Windows can do).

On the SAP side, generate a consumer proxy from the WSDL file, and write a program that uses the generated proxy classes to call the web service. (This is also standard stuff,. and documented in help.sap.com, and blogs/wiki entries on this site).

Using web services to manage communications between two computer systems is an industry wide technology.

UmaArjunan
Active Participant
0 Kudos

Hi Matthew,

" " The web service ran a batch file with supplied parameters. " " Is this batch file ( with some instructions / rules / commands ) running in Foreground ? Pl. clarify.

Thanks, Uma

matt
Active Contributor
0 Kudos

Like logged into windows and with a command console you might run

MyBatch.bat param1 param2

roberto_vacca2
Active Contributor
0 Kudos

Hi.

My suggest is trying to use simple different command as "ls" for unix or "dir" for windows and see what happens. If your problem is your actual working directory you should launch before an other command to change it. What do you mean with "RFC is always failing", what's the message?

Hope to help

Bye

UmaArjunan
Active Participant
0 Kudos

already tried with ls , ls is listing the files in the working directory and i could see the output in sm69 .

RFC connection is the connection created for connecting to Remote desktop through standalone gateway. if we execute this connection in sm59 to connect to RDP, it is successful

Target dest option is used to execute the external commands by choosing the RFC connection.

and the external command i m executing is \\sharepathid\test\test.bat ( share path of the Windows RDP ) it looks like the below

Error when executing external commands pl refer the screen print of SM21


roberto_vacca2
Active Contributor
0 Kudos

You mean commands in test.bat?

In that case I'm agree with Matthew, once you'll have a webservice on windows server that could be consumed, you can get an XML reply in ABAP.

I put here some screen to show how could be a web-service call from ABAP to Windows System.

For a windows web service implementation there are lot of documentation on internet.

Hope to help

Bye

WebServiceDocument