Re: xp_cmdshell

From: Michael C (xyz_at_abcdef.com)
Date: 10/22/04


Date: Fri, 22 Oct 2004 00:16:18 GMT

Just create a regular batch (.BAT) file, save it in the root dir and invoke
using

exec xp_cmdshell 'c:\mybatch.bat'

where mybatch.bat is the name of your batch file. Note - I haven't actually
tried this, but it *should* work. xp_cmdshell just invokes the same command
line shell you invoke when you go to Start > Run and enter cmd.

Thanks,
Michael C., MCDBA

"George Meng" <m20010921@hotmail.com> wrote in message
news:%230TMyF8tEHA.3016@TK2MSFTNGP12.phx.gbl...
> Thanks Mike & Jeff.
>
> Is there a way to run a bacth file within xp_cmdshell? I look at the SOL,
> but didn't get any such information.
>
> Thanks again.
>
> "Michael C" <xyz@abcdef.com> 写入消息新闻
> :CGWdd.39846$YM4.13129115@news4.srv.hcvlny.cv.net...
>> I would imagine that xp_cmdshell is using the command shell directory on
>> your PC (i.e., the Windows\System32 directory). Each call to xp_cmdshell
>> invokes a new instance of of the command line shell, using the default
>> system directory. Try specifying your directory explicitly in the dir
>> command like this:
>>
>> exec xp_cmdshell 'dir c:\'
>>
>> The cd command actually works in xp_cmdshell, but only in the current
>> instance of the command line shell that's invoked. You'd probably have
>> to
>> write a batch file or some such to get any benefit from the cd command in
> an
>> xp_cmdshell instance.
>>
>> Thanks,
>> Michael C., MCDBA
>>
>> "George Meng" <George Meng@discussions.microsoft.com> wrote in message
>> news:F6492316-490C-49FC-88F0-C1CCC0B4E6CD@microsoft.com...
>> >I got a issue with xp_cmdshell
>> >
>> > I have only one hard drive. so when I run the following T-SQL, I expect
> to
>> > see file list in C:\:
>> >
>> > exec xp_cmdshell 'cd\'
>> > exec xp_cmdshell 'dir'
>> >
>> > how ever, it still give me file list under: C:\WINDOWS\system32.
>> >
>> > I just don't understand, it seems that 'CD' does not work well with
>> > xp_cmdshell.
>> >
>> > I have tested this SQL under SQL Server 2000 and Windows XP/2000.
>> >
>> > Thanks very much!
>> >
>> >
>>
>>
>
>



Relevant Pages


Quantcast