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
 Exec bat file using Execute master..xp_cmdshell

Author  Topic 

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-07-14 : 21:08:31
Guys I was able to run this bat file in command prompt
"X:\PG\SB\test.bat" "X:\PG\SB\test.dat" 255 pgservername test test_dat

It basically creates the table test_dat in test db and loads the file test.dat using LogParser2_2. I wanted to run this in Sql Proc using below:

EXECUTE master..xp_cmdshell '"X:\PG\SB\test.bat" "X:\PG\SB\test.dat" 255 pgservername test test_dat'

It did not do what was supposed to and gave me

The filename, directory name, or volume label syntax is incorrect.
and a blank row as Output... Anyone with such experience?

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-14 : 23:50:25
xp_cmdshell runs under the context of the sql server service account. make sur eservice account has permissions on the share. also, use unc path, not mapped drive...service account probably doesn't recognize x:

if this is a sql agent job, no need to use xp_cmdshell either...better to make job type of operating system command
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-07-15 : 00:31:24
service account has permission... I gave the full path even that did not work...I am able to use bcp utility using that path...probably something I am missing. You have good points that I did not think about earlier thanks!
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-15 : 05:29:05
can we see the contents of the batch file?

LogParser is installed on sql server?
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-07-17 : 12:52:55
Thanks Russell I was able to work around my issue... it was not liking the double quotes around bat file. This is to handle true CSV file... Can anyone tell me how to handle Pipe Delimited files?

This is the bat script:
@ECHO OFF

REM Input File = %1; Max Field Length = %2; Target Server = %3; Target Database = %4; Target Table = %5

@ECHO ON

LogParser -i:CSV -iCodepage:0 -headerRow:ON -fixedFields:ON -dtLines:10 -nFields:-1 -o:SQL -server:%3 -database:%4 -createTable:ON -clearTable:ON -maxStrFieldLen:%2 -ignoreMinWarns:OFF "SELECT * INTO %5 FROM %1" -e:0 -iw:ON -q:ON
Go to Top of Page
   

- Advertisement -