Home > Archive > SQL Anywhere database > June 2005 > Help with this command xp_cmdshell









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help with this command xp_cmdshell
Napoli

2005-06-15, 8:24 pm

I am calling xp_cmdshell (c:\\temp.bat', 'no_output' ) from
with in a trigger. The problem I am having is that the
trigger doesnot continue until the bat file has executed.
Is there any way to tell the trigger to continue without
worrying about the bat file, just call the bat file and
continue to do what it needs to do?
Mark Culp

2005-06-16, 3:24 am

xp_cmdshell, but design, will wait for the command to complete
before returning (and allowing the execution of your trigger to
continue).

I can think of two ways of doing what you want:
1) fire an event within your trigger, and then make the event
call xp_cmdshell
2) make your external command (temp.bat in this case) spawn a
process that does the real work
--
Mark Culp
SQLAnywhere Research and Development
-------------------------------------------------------------------------
** Whitepapers, TechDocs, bug fixes are all available through the **
** iAnywhere Developer Community at http://www.ianywhere.com/developer **
-------------------------------------------------------------------------
* <<<<< Please always include the ASA version and build number >>>>> *
* <<<<< _and_ the operating system version that you are using >>>>> *
-------------------------------------------------------------------------

Napoli wrote:
>
> I am calling xp_cmdshell (c:\\temp.bat', 'no_output' ) from
> with in a trigger. The problem I am having is that the
> trigger doesnot continue until the bat file has executed.
> Is there any way to tell the trigger to continue without
> worrying about the bat file, just call the bat file and
> continue to do what it needs to do?

Napoli

2005-06-16, 3:24 am

The ASA Version is 9.0.1 and the operating system is Win 2K
Server. Can you give me an example of what you are talking
about?
[color=darkred]
> xp_cmdshell, but design, will wait for the command to
> complete before returning (and allowing the execution of
> your trigger to continue).
>
> I can think of two ways of doing what you want:
> 1) fire an event within your trigger, and then make the
> event
> call xp_cmdshell
> 2) make your external command (temp.bat in this case)
> spawn a
> process that does the real work
> --
> Mark Culp
> SQLAnywhere Research and Development
> ----------------------------------------------------------
> --------------- ** Whitepapers, TechDocs, bug fixes are
> all available through the ** ** iAnywhere Developer
> Community at http://www.ianywhere.com/developer **
> ----------------------------------------------------------
> --------------- * <<<<< Please always include the ASA
> version and build number >>>>> * * <<<<< _and_ the
> operating system version that you are using >>>>> *
> ----------------------------------------------------------
> ---------------
>
> Napoli wrote:
Reg Domaratzki \(iAnywhere Solutions\)

2005-06-16, 9:23 am

When this command is executed, a DOS windows opens and waits for you to hit
any key. While the DOS windows is open, executing does not continue in the
trigger :

xp_cmdshell( 'pause' );

When this command is executed, a DOS windows opens, which opens another
window that waits for you to hit any key. Since the command "start pause"
has finished executing, execution can continue in the trigger while the 2nd
DOS window waits for you to hit any key :

xp_cmshell( 'start pause' );

--
Reg Domaratzki, Sybase iAnywhere Solutions
Sybase Certified Professional - Sybase ASA Developer Version 8
Please reply only to the newsgroup

iAnywhere Developer Community : http://www.ianywhere.com/developer
iAnywhere Documentation : http://www.ianywhere.com/developer/product_manuals
ASA Patches and EBFs : http://downloads.sybase.com/swx/sdmain.stm
-> Choose SQL Anywhere Studio
-> Set "Platform Preview" and "Time Frame" to ALL

<Napoli> wrote in message news:42b0e629.1aaf.1681692777@sybase.com...[color=darkred]
> The ASA Version is 9.0.1 and the operating system is Win 2K
> Server. Can you give me an example of what you are talking
> about?
>


Reg Domaratzki \(iAnywhere Solutions\)

2005-06-16, 9:23 am

I should have used :

call xp_cmdshell( 'start /c pause' )

in my second example so that the windows closes when pause finishes.

--
Reg Domaratzki, Sybase iAnywhere Solutions
Sybase Certified Professional - Sybase ASA Developer Version 8
Please reply only to the newsgroup

iAnywhere Developer Community : http://www.ianywhere.com/developer
iAnywhere Documentation : http://www.ianywhere.com/developer/product_manuals
ASA Patches and EBFs : http://downloads.sybase.com/swx/sdmain.stm
-> Choose SQL Anywhere Studio
-> Set "Platform Preview" and "Time Frame" to ALL

<Napoli> wrote in message news:42b0e629.1aaf.1681692777@sybase.com...[color=darkred]
> The ASA Version is 9.0.1 and the operating system is Win 2K
> Server. Can you give me an example of what you are talking
> about?
>


Greg Fenton

2005-06-16, 9:23 am

Napoli wrote:
> The ASA Version is 9.0.1 and the operating system is Win 2K
> Server. Can you give me an example of what you are talking
> about?



For method #1:

CREATE EVENT RunMyShellScript
HANDLER
BEGIN
call xp_cmdshell('c:/temp.bat', 'no_output');
END;

CREATE TRIGGER bi_MyTable
BEFORE INSERT ON MyTable
BEGIN
TRIGGER EVENT RunMyShellScript
END;


Note the above has not been tested or syntax checked at all.
Also note that an EVENT's handler runs in a separate database connection
from the one that triggers it. Whatever happens in the EVENT cannot be
communicated back to the caller, and its actions occur entirely in a
separate transaction.

For more info, see the "CREATE EVENT" and "TRIGGER EVENT" statements in
the SQLAnywhere docs.

Hope this helps,
greg.fenton
--
Greg Fenton
Consultant, Solution Services, iAnywhere Solutions
--------
Visit the iAnywhere Solutions Developer Community
Whitepapers, TechDocs, Downloads
http://www.ianywhere.com/developer/
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com