Results 1 to 3 of 3

Thread: about xp_cmdshell

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    about xp_cmdshell

    Hi There,

    is it possible to update certain line of text in notepad file using xp_cmdshell in mssql?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: about xp_cmdshell

    Basically, whatever you can do with the Shell function in VB6 or the Process.Start function in VB.NET, you can do with xp_cmdshell in SQL Server.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: about xp_cmdshell

    a little help here..i already read whatever text in the notepad using stored procedure but i don't know how to modify certain line of text..how will i solve this?

    this my sp..
    Code:
    set nocount on
    
    create table #file_contents (
      line_number int identity,
      line_contents nvarchar(4000)
    )
    
    declare @file_contents nvarchar(4000)
    declare @new_line char(2)
    
    
    set @new_line = char(13) + char(10)
    
    insert #file_contents
    exec master.dbo.xp_cmdshell 'type c:\sample.txt'
    
    select @file_contents =
      isnull(@file_contents, '') + @new_line +
      isnull(line_contents, '')
    from #file_contents
    
    select @file_contents
    
    drop table #file_contents
    
    set nocount off

Posting Permissions

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



Click Here to Expand Forum to Full Width