We have a small standalone non-visual application written in powerbuilder that we would like to startup from a SA11 stored procedure. Once running, the program will carry out its activities and end when complete.

How do we script this in a stored procedure?

Are there any special considerations?

asked 26 Jul '12, 17:49

Glenn%20Barber's gravatar image

Glenn Barber
accept rate: 0%

The only way to do this would be to use the xp_cmdshell() system procedure. The first thing that comes to mind is that the procedure will wait for the external application to complete before finishing.

permanent link

answered 26 Jul '12, 19:56

Calvin%20Allen's gravatar image

Calvin Allen
accept rate: 25%

Thanks Calvin - just what I was looking for - otherwise Id have to do some wrapper around my app so it could be called.

(26 Jul '12, 20:01) Glenn Barber
Replies hidden

FWIW you can make it asynchronous (fire-and-forget instead of call-and-return) in Windows by using "start"...

@rc = CALL xp_cmdshell ( 'start notepad', 'no_output' );

For one of the more insane examples, see http://sqlanywhere.blogspot.ca/2012/01/you-cant-do-that-in-sql.html

(27 Jul '12, 06:51) Breck Carter

Ah, nice solution!

(27 Jul '12, 09:26) Calvin Allen

Thanks Calvin and Breck - this was very helpful...I was going blind trying to find this in the documentation.

(27 Jul '12, 12:12) Glenn Barber

Hi Breck

While I can get

@rc = call xp_cmdshell('"c:\Program Files\Appdir\myapp.exe"','no_output') to run

@rc = call xp_cmdshell('Start "c:\Program Files\Appdir\myapp.exe"','no_output') just brings up a blank cmd window

Any suggestions on syntax here?


(27 Jul '12, 19:33) Glenn Barber

@rc = call xp_cmdshell('Start /D"c:\Program Files\Appdir" /B myapp.exe','no_output') works

(27 Jul '12, 21:39) Glenn Barber

@Glenn: I see you've discovered the "help start" docs available in a command window :)

If memory serves, different versions of DOS/Windows support different flavors of START so don't go crazy with the syntax if you have to deploy to multiple platforms.

Plus, as you can see by examples that work without /D, including http://sqlanywhere.blogspot.ca/2012/01/you-cant-do-that-in-sql.html, START is inconsistent in its requirements. I believe the parser is feeble and sometimes confuses a "command" parameter with the optional "title", hence the empty window.

As a final take-away, questions like "how do I call xp_cmdshell" work well in Google, especially here since xp_cmdshell exists in SQL Server as well. Or, to keep it in the family, you can google this:

how do I call xp_cmdshell site:sybase.com
(28 Jul '12, 05:56) Breck Carter
showing 2 of 7 show all flat view
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 26 Jul '12, 17:49

question was seen: 2,125 times

last updated: 08 Aug '12, 18:22