Application Development 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: 

Executing external commands(vbscript from network drive)

Former Member
0 Kudos
844

Hello All,

There is a client requirement where a certain number of steps need to be automated as a background job. The current manual process is such that first a vbscript is run, which creates a temporary folder and connects to a FTP location and pick data and dump it into this temporary folder on the network drive. Then a standard SAP program uses this file from the defined path and is executed. Then another vbscript is run, which basically archives the files to a different folder. These steps need to be automated.

Now we can use the cscript command in DOS to execute a .vbs script file. but this will not work with GUI_EXEC as this will fail in background. Will SXPG_COMMAND_EXECUTE/SXPG_CALL_SYSTEM fucntion modules work in this case ? I have not used them, so will they execute the command on the presentation server as I am guessing these work on the application server with the command created in SM69 ?

Thanks and Regards,

Sachin

1 ACCEPTED SOLUTION

bbalci
Contributor
0 Kudos
146

Hi Sachin

Yes SM69 / SXPG_COMMAND_EXECUTE / SXPG_CALL_SYSTEM are used to

send commands to application server in Microsoft and UNIX systems.

Than it's the solution for background purposes.

I've used them ".sh" files in a unix system and ".bat" files in a microsoft system

and they was running successful.

SXPG_COMMAND_EXECUTE just sends an execution commands to operating system

remaining work is on the server.

It means if you can run manually that script files on your .vbs application server

you can run it with SXPG_COMMAND_EXECUTE too.

I hope it can be helpful.

7 REPLIES 7

bbalci
Contributor
0 Kudos
147

Hi Sachin

Yes SM69 / SXPG_COMMAND_EXECUTE / SXPG_CALL_SYSTEM are used to

send commands to application server in Microsoft and UNIX systems.

Than it's the solution for background purposes.

I've used them ".sh" files in a unix system and ".bat" files in a microsoft system

and they was running successful.

SXPG_COMMAND_EXECUTE just sends an execution commands to operating system

remaining work is on the server.

It means if you can run manually that script files on your .vbs application server

you can run it with SXPG_COMMAND_EXECUTE too.

I hope it can be helpful.

Former Member
0 Kudos
146

Thanks for the prompt reply.

The problem is that the scripts are stored on a network drive which I presume would be the presentation server. If I write a .bat file with say the content as cscript d:\example.vbs, it will not execute the script which is stored on the network drive and instead it will search for the same on the application server. Is this what its going to do ? Is it possible to run the script on the presentation server ?

Thanks and Regards,

Sachin

0 Kudos
146

In the script you must write the appropriate command to access the file in the network.

I have done this long before, the command will hold the credentials , path etc . have to do some work around like this.

0 Kudos
146

Hi Sachin,

In windows operating system

I use "map network drive" option to use a network drive from my own computer

than I specify a shortcut path like "f:\" .

( it's a originally a path like "192.168.1.1\scripts\.." etc but it's just "f:" in my computer

because I set it as a network drive )

After that I can use this just like a local drive on my own computer,

and executables and scripts runs on my computer system but stored on that drive.

You can follow the same method,

describe a shortcut to folder of scripts wherever they stored and execute them on your own server.

>Is it possible to run the script on the presentation server ?

You want to use scripts in background too, a presentation server stands for the terminal

which a user logs on to SAP. Than it's not possible. You have to an IP or network drive path.

Edited by: Bulent Balci on Aug 17, 2010 12:00 PM

Former Member
0 Kudos
146

Thanks,

Yes, mapping it to a network drive and then executing is fine, that I have tried, but the problem is that this can not be done using the SXPG_ function module as it will be executed on the application server.

The VBScript program has code to create a temporary folder, but when it is executed on the application server it will not create or execute the file on the presentation server.

Thanks and Regards

Sachin

0 Kudos
146

You didn't mention about the temporary folder

Than I can advice u 2 options :

1- use same network drive path for the temporary folder creation in your VBScript code.

by this way your temporary files will be created on other server not the application server,

and you could have a problem of network load.

2- go to transaction AL11 create a folder for your temporary needs on application server

and always use this folder in your VBScript code .

But your script has to be authorized for file access on the operating system of application server off course

maybe that could be a problem and you'll need a basis guy.

Good luck.

Edited by: Bulent Balci on Aug 17, 2010 12:40 PM

0 Kudos
146

hi all,


You don't have to create a System Commands in transaction SM69 to be able to execute the VBScript or other script within the program in background mode.

When calling function "WS_EXECUTE" just add the "In Background Task" at the end to execute the VBscript or other scripts.

This  extra line "In backround task" should not raise the exception

CL_GUI_FRONTEND_SERVICES======CP.

it should look like this.

data: commandline(1000).

commandline = 'P:\sapfrontend.vbs'.

  call function 'WS_EXECUTE' in BACKGROUND TASK
       exporting
            commandline    = commandline
            program        = 'WSCRIPT.EXE'
       exceptions
            frontend_error = 1
            no_batch       = 2
            prog_not_found = 3
            illegal_option = 4
            others         = 5.