Jump to content

How-to execute a command line


ricky
 Share

Recommended Posts

Hello,

I have a command line to execute in a dos prompt, but my command line as a quote and double-quote, how can I execute it?

Line : osql -E -S .SQLEXPRESS -h-1 -Q "SET NOCOUNT ON; SELECT 'Version=', CONVERT(NVARCHAR,SERVERPROPERTY('productversion'))"

My function to execute the command line :

Func DosCommand($command)

    Local $foo, $line, $temp

    $foo = Run(@ComSpec & " /c " & $command, @ScriptDir, @SW_HIDE, 2); $STDOUT_CHILD = 2  De Constants.au3

    While 1
        $line = StdoutRead($foo)
        If @error Then ExitLoop

        If $line <> "" Then $temp &= _OEMToAnsi($line)
    WEnd

    Return $temp

EndFunc   ;==>DosCommand

Func _OEMToAnsi($sOEM)
    ; http://autoitscript.fr/forum/viewtopic.php?f=21&t=4108&hilit=conversion+OEM+ANSI
    Local $sAnsi
    Local $a_AnsiFName = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $sOEM, 'str', '')
    If @error = 0 Then $sAnsi = $a_AnsiFName[2]
    Return $sAnsi
EndFunc   ;==>_OEMToAnsi

Thanks for your help

Link to comment
Share on other sites

Hello,

thanks, in first test it doesn't work because a quote  before Version is not necssary, working line :

$command = 'osql -E -S .\SQLEXPRESS -h-1 -Q "SET NOCOUNT ON; SELECT ' & "'Version=', CONVERT(NVARCHAR,SERVERPROPERTY('productversion'))" & '"'

Thanks a lot!

Edited by ricky03
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...