Questions tagged [xp-cmdshell]

an extended stored procedure provided by SQL Server, which launches a Windows command shell to run a specified command. Not for general questions about cmd.exe or batch scripting; not related to Windows XP.

The xp_cmdshell extended stored procedure runs the command string given and returns any output as rows of text. The documentation (for SQL Server 2012) can be found here.

For security reasons, xp_cmdshell is disabled by default in recent versions of SQL Server.

264 questions
0
votes
1 answer

SQL server how stop process run from xp_cmdshell

i try open folder from my computer by run script in sql server EXEC xp_cmdshell 'start C:\folder' it folder not exixt and the process still execute then i do kill process but it still KILLED/ROLLBACK what to do now? help!! michal
michal
  • 5
  • 3
0
votes
0 answers

xp_cmdshell quotations and arguments size issue

I am trying to pass large html from ms sql to exe file by: EXEC master..xp_CMDShell 'c:\path\index.exe' --body="
1110
  • 7,829
  • 55
  • 176
  • 334
0
votes
1 answer

Write to .html file with exec master..xp_cmdshell

Below is my small code: Scenario 1 declare @DataToWrite varchar(8000) set @DataToWrite='

This is a Heading

' DECLARE @CommandL1 varchar(8000) SET @CommandL1 = 'echo'+@DataToWrite+'>…
0
votes
1 answer

xp_cmdshell throwing 'null' but working in command prompt

I am using xp_cmdshell command to process csv file to a folder. My query is as below: Exec master..xp_cmdshell 'C:\test\mydotnetapp.exe -s:03/09/2020 -t:1 -l:1,2,3,4,7 -d C:\test' In SSMS this command returns null. But in command prompt when I…
Rick
  • 1,392
  • 1
  • 21
  • 52
0
votes
2 answers

Workaround for xp_cmdshell in Azure SQL Database

Stored procedure in on-premises SQL Server is used to call another app through 'xp_cmdshell'. Now I am trying to do the same on Azure SQL Database. Of course 'xp_cmdshell' is not supported there, so I need workaround. I was thinking of using Azure…
0
votes
1 answer

Use xp_cmdshell and bcp utility not working

Running these on SQL server 2014 SP3 EXEC master..xp_cmdshell 'dir c:\' -- This is working ** The following is on a single row ** EXEC master..xp_cmdshell 'bcp "select name, type_desc, create_date from sys.objects" queryout "c:\bcptest2.txt" -T…
0
votes
0 answers

SQL xp_cmdshell Keeps Running and Won't Cancel

I'm trying to run a xp_cmdshell to execute a program and thought I'd test it by opening notepad. However when I execute the command it just keeps on executing without returning results or opening notepad. Then, when I try to cancel the execution,…
ptownbro
  • 1,240
  • 3
  • 26
  • 44
0
votes
1 answer

Not able to delete a read only file in directory from sql server

I have executed the following query in my local system and its works fine for normal file (files that not have read only attribute). But, when I tried this for read only file the sql server prompts 'Access is Denied'. Declare @execmd…
0
votes
0 answers

Why is my stored procedure working fine when executed manually, but not when called from another SP?

I have a stored procedure which performs following steps: it updates a default values table for the software, and just runs a powershell cmdlet which is reload tradeloader defaults The stored procedure takes a parameter like DefaultValue=ABC, where…
0
votes
0 answers

Open text file programmatically via xp_cmdshell & python os.system

I'm writing an application that requires a text file to automatically pop open (visible to the user client) after a sequence of database processes are completed. At the end of a SQL file, I have an xp_cmdshell command that reads: exec xp_cmdshell…
emalcolmb
  • 1,585
  • 4
  • 18
  • 43
0
votes
0 answers

xp_cmdshell not generating the file on specified location

I'm using xp_cmdshell bcp to generate CSV file from the output, But I'm not able to generate the file, it gives me following output when executed. I get this as the output, I'm not sure what is going on as I do not have much of hands on using…
Nuthan Gowda
  • 255
  • 3
  • 6
  • 19
0
votes
1 answer

SQL Server stored procedure xp_cmdshell powershell.exe syntax to skip 1 row when importing from a csv file

The PowerShell part of the syntax I have added works fine when executing it in PowerShell on Windows 10, but when I use it in SQL Server: Exec xp_cmdshell 'powershell.exe Get-Content "c:/temp/test1.csv" |Select-Object -Skip 1 | Out-File…
Ej1
  • 1
  • 1
  • 1
0
votes
0 answers

Procedure does not work in a trigger. Without trigger, the system procedure works fine

When I execute this procedure without a trigger, it all works fine EXEC sys.XP_CMDSHELL 'bcp "select * from users FOR JSON AUTO;" queryout E:\temp\JsonExport.json -t, -c -S . -d learntrigger -T' but if I have created the trigger and make an INSERT,…
0
votes
1 answer

Put SELECT into .csv file

I'm using this code to create .csv file, but nothing happenes. DECLARE @csvFileName varchar(50) DECLARE @SelectOut varchar(8000) SET @csvFileName = 'D:\csv Files\' + CAST(year(SYSDATETIME()) AS VARCHAR) + CAST(month(SYSDATETIME()) AS…
user11247649
0
votes
1 answer

How to get escape characters to behave through sql server's xp_cmdshell with command with Caret

I'm trying to print from a SQL Server stored procedure to a Label printer using ZPL with variables and a network printer I've tested the ZPL to make sure it's working and then learned how to pass it through a PowerShell script to get it to print to…