Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Posts
    25

    Unanswered: Trouble exporting sysprocesses to text file through xp_cmdshell

    Hi,

    Using SQL Server 2000.

    All I'm trying to do is get the results of
    Code:
    SELECT
    db.name,
    p.spid,
    p.login_time,
    p.status,
    p.hostname,
    p.program_name,
    p.cmd,
    p.loginame
    FROM sysprocesses p
    INNER JOIN sysdatabases db ON db.dbid = p.dbid
    into a text file on my c drive.


    I've tried using bcp and osql:

    Code:
    EXEC master..xp_cmdshell
    'bcp "select * from sysprocesses" queryout C:\Documents and Settings\chris_h\Desktop\Log.txt -c -Usa -P'
    The above returns an error 'Unknown argument 'and' on command line.'

    Code:
    EXEC master..xp_cmdshell 'osql.exe -S CHRIS-H-XP -E -Q "EXEC master..sysprocesses" -o "C:\Documents and Settings\chris_h\Desktop\Log.txt"'
    The above writes the following into the text file: Msg 2809, Level 18, State 1, Server CHRIS-H-XP, Line 1
    The request for procedure 'sysprocesses' failed because 'sysprocesses' is a view object.'


    Please help

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    The filepath contains spaces and therefore must be qualified using quotes:
    Code:
    EXEC master..xp_cmdshell
    'bcp "select * from sysprocesses" queryout "C:\Documents and Settings\chris_h\Desktop\Log.txt" -c -Usa -P'
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •