Sign in to follow this  
Followers 0
ricky

How-to execute a command line

5 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Edit: too many ' char

Edited by michaelslamet

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Hello,

no, doesn't work!

 

Sorry that I type too much ' char. Please try the edited post above

Share this post


Link to post
Share on other sites

I edit at the same time. Thanks!

Share this post


Link to post
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
Sign in to follow this  
Followers 0