Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 xp_cmdshell open a batch file

Author  Topic 

visa123
Yak Posting Veteran

54 Posts

Posted - 2010-09-29 : 02:46:48
Hi


I have to open a batch file automatically in sql. So i have used the below command.

EXECUTE master.dbo.xp_cmdshell 'D:\Databases\batch\123.bat'

Its worked for few times. After that its not working.

One time i have stopped before the process is complete.May be this is the issue.

Now its returns null value.


Can anyone help me how can i open the file in sql.





Visa.G

visa123
Yak Posting Veteran

54 Posts

Posted - 2010-09-29 : 05:36:34
Hi

I have used the below code to enable the xp_cmdshell.

EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE

GO
EXEC sp_configure 'xp_cmdshell', 1

But when i execute the below statement it returns NULL value only.
Can anyone help me?

EXECUTE master.dbo.xp_cmdshell 'D:\Databases\batch\123.bat'

Thanks



Visa.G
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-09-29 : 05:56:46
Does this path 'D:\Databases\batch\123.bat' exists on the SQL server?

PBUH

Go to Top of Page

visa123
Yak Posting Veteran

54 Posts

Posted - 2010-09-29 : 07:43:58
Hi

Yes.The Path is Exists.I have checked manually to open batch file in this path.

It working fine.But through that 'xp_cmdshell' it is not working.

Thanks

Visa.G
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-09-29 : 08:00:46
Are you running xp_cmdshell under sysadmin?

PBUH

Go to Top of Page

visa123
Yak Posting Veteran

54 Posts

Posted - 2010-09-29 : 08:22:46
Yes sysadmin only

Visa.G
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-09-29 : 09:27:02
are you getting an error? what does the batch file do?
Go to Top of Page

visa123
Yak Posting Veteran

54 Posts

Posted - 2010-09-29 : 09:33:08
i am not getting any Error.The output is showing NULL.

The batch file open One url ( that is Transferring the data for Our client request ).

If i open the batch manually , its fine.but through this cmdshell returing null output.



Visa.G
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-09-29 : 09:41:51
is the batch file executing?
Go to Top of Page

visa123
Yak Posting Veteran

54 Posts

Posted - 2010-09-29 : 09:50:26
yes. In this Batch file i have included the below code.

Below is the example

start http://test.com/sampledatatransfer.aspx



Visa.G
Go to Top of Page
   

- Advertisement -