analliah
asked on
Shell String in VB.net
I have a VB.Net to perform encryption of files using PGP.
The line of argument,that is passed in the DOS Window is as below.
gpg --recipient "XXX" --output "C:\Filename.zip.gpg" --encrypt "C:\Filename.zip"
Here is my Function in VB.net.
Dim GPG As New FileInfo("C:\Program Files\GNU\GnuPG\gpg.exe")
Dim sGPGLocation As String
Dim sCommandLine As String = Nothing
Dim extension = ".gpg"
'gpgEncryptName would be passed from a function eventually
Dim gpgEncryptName As String = "C:\Testing.zip"
Dim publicKey As String = "XXX"
'-------Ensure we can find GPG.exe------
If GPG.Exists = True Then
sGPGLocation = "C:\Program Files\GNU\GnuPG\gpg.exe"
Else
Console.WriteLine("Error: Couldn't find GPG.EXE")
'Return False
End If
sCommandLine = """ & --recipient & """" """" "" & publicKey & "" """" """" & --output & """" """" "" & gpgEncryptName & extension & "" """" """" & --encrypt & """" """" "" & gpgEncryptName & """
Console.WriteLine(sCommand Line)
Shell("""--recipient & """ """ & publicKey & """ """ & --output & """ """ & gpgEncryptName """" & """" extension & """" --encrypt """" & """" gpgEncryptName """)
'Return True
Catch ex As IOException
Console.WriteLine("Unable to locate GPG Software")
How can I represent gpg --recipient "XXX" --output "C:\Filename.zip.gpg"
--encrypt "C:\Filename.zip"
in the Shell.Im not very familiar on how to represent empty space and [""] in the String.
The line of argument,that is passed in the DOS Window is as below.
gpg --recipient "XXX" --output "C:\Filename.zip.gpg" --encrypt "C:\Filename.zip"
Here is my Function in VB.net.
Dim GPG As New FileInfo("C:\Program Files\GNU\GnuPG\gpg.exe")
Dim sGPGLocation As String
Dim sCommandLine As String = Nothing
Dim extension = ".gpg"
'gpgEncryptName would be passed from a function eventually
Dim gpgEncryptName As String = "C:\Testing.zip"
Dim publicKey As String = "XXX"
'-------Ensure we can find GPG.exe------
If GPG.Exists = True Then
sGPGLocation = "C:\Program Files\GNU\GnuPG\gpg.exe"
Else
Console.WriteLine("Error: Couldn't find GPG.EXE")
'Return False
End If
sCommandLine = """ & --recipient & """" """" "" & publicKey & "" """" """" & --output & """" """" "" & gpgEncryptName & extension & "" """" """" & --encrypt & """" """" "" & gpgEncryptName & """
Console.WriteLine(sCommand
Shell("""--recipient & """ """ & publicKey & """ """ & --output & """ """ & gpgEncryptName """" & """" extension & """" --encrypt """" & """" gpgEncryptName """)
'Return True
Catch ex As IOException
Console.WriteLine("Unable to locate GPG Software")
How can I represent gpg --recipient "XXX" --output "C:\Filename.zip.gpg"
--encrypt "C:\Filename.zip"
in the Shell.Im not very familiar on how to represent empty space and [""] in the String.
ASKER
This is what I get
" --recipient "XXX" --output "C:\Testing.zip.gpg" --encrypt "C:\Testing.zip""
There is an extra " " at the very begining and end.
What does chr(34) represent ?
Is there a special character for space as well?
" --recipient "XXX" --output "C:\Testing.zip.gpg" --encrypt "C:\Testing.zip""
There is an extra " " at the very begining and end.
What does chr(34) represent ?
Is there a special character for space as well?
chr(34) is the equivalent of "If you don't need the others, simply remove them, but I think these are actually in the next line...no?sCommandLine = " --recipient " & chr(34) & publicKey & chr(34) & " --output " & chr(34) & gpgEncryptName & extension & chr(34) & " --encrypt " & chr(34) & gpgEncryptName & chr(34)Console.WriteLine(s CommandLin e)'Changin g this next line work?Shell(sCommandLine)
ASKER
My bad.It works fine.Thank You
What does chr(34) represent ?
Is there a special character for space as well?
What does chr(34) represent ?
Is there a special character for space as well?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sCommandLine = " --recipient " & chr(34) & publicKey & chr(34) & " --output " & chr(34) & gpgEncryptName & extension & chr(34) & " --encrypt " & chr(34) & gpgEncryptName & chr(34)