I have a bash command which I need to run in vb.net.
The command is like that:
for i in `seq 0 2` & ";" & "do ./abc.sh ""xyz -d $i" """" ";" & "done"
I tried multiple ways, using Shell(command) and
Dim psi As New ProcessStartInfo(exePath)
Dim cmdSession As New Process
psi.WorkingDirectory = WorkingDirectory
psi.FileName = "cmd.exe"
psi.UseShellExecute = True
psi.Arguments = "ls"
psi.WindowStyle = ProcessWindowStyle.Maximized
cmdSession.StartInfo = psi
cmdSession.Start()
but no success. Can anyone help me in executing these commands from bash shell. Tried searching other threads but no help.
Related
I have this code, and I´m calling one Java program to pass the aurguments, that I select in VB.
My issues is:
The cmd windows open, but I can't see what the program is doing, I only see on the window the arguments that are pass, and when finish, the window don't close.
enter image description here
and when program stop, the windows don't close.
enter image description here
This is the result if I run by command line
enter image description here
txbSendCommand.Text = "java -jar FACTEMICLI-2.5.16-33194-cmdClient.jar " & "-i " & TextBox1.Text & "" & " -n " & stNIF & " -p " & stPassword & " -a " & iAno & " -m " & iMes & " -op " & stvalidar & stFicheiroEscolhido & " -o c:\saft\outputfile.xml"
Dim stcaminhoexterno As String
If stErrorMessage = False Then
Dim app As New ProcessStartInfo("cmd.exe") With {.RedirectStandardInput = True, .UseShellExecute = False, .CreateNoWindow = False}
Dim myProcess As New Process
myProcess = Process.Start(app)
Dim arguments As String = txbSendCommand.Text
myProcess.StandardInput.WriteLine(arguments)
myProcess.Close()
End If
How can I see the results in the external windows, or better even in a windows or something that I can have in the form.
How Can the window close after the process is done
I've written code in VB to run a CMD command, where the output is stored to a text file. This output is then needed for the program, so the program needs to wait until the CMD command has finished before continuing. I am using
Dim wait As Process = Process.Start(psi)
wait.WaitForExit()
To make sure the process exits before the code continues, but now that I've done that, the "/c" option in the process info is no longer working. The process info is as follows:
Dim psi As New ProcessStartInfo With {
.FileName = "Cmd",
.Arguments = "/c " & completedCom & " > " & oPath
}
I do not understand why the "/c" option would fail all of a sudden.
Spaces would be an example of one problem. Use quotes around your commands to help with that:
Dim psi As New ProcessStartInfo With {
.FileName = "Cmd",
.Arguments = "/c """ & completedCom & """ > """ & oPath & """"
}
The preferred method of calls to process would be to directly call the exec, rather than launching a cmd. In that case, you would have to capture the standard output asynchronously and write it to a file though.
I am trying to run shell commands from VBA and get output into a csv file. Below is the code I am using:
Dim wsh as Object
Set wsh = VBA.CreateObject("WScript.Shell")
plink_path="C:\plink.exe"
key_path="putty key path"
pass_query="select * from test"
command1 = Replace(plink_path & " hadoop#11.11.11.11 -i " & key_path & " mysql -uuser -ppass -e 'use radar;" & pass_query & "'", Chr(10), " ")
wsh.Run command1 & ">E:/anurag.csv", 0, True
But I am not able to view output file in the E drive. When I run the above command manually from a cmd prompt I do get an output in the E drive.
Two thoughts:
Try E:\anurag.csv instead of E:/anurag.csv
Use cmd to invoke plink, since cmd usually processes the redirections. Replace the wsh.Run line with:
command1 = command1 & ">E:\anurag.csv"
command1 = "cmd /c """ & command1 & """"
wsh.Run command1, 0, True
The first line completes the command you wanted to execute and the second wraps it in a cmd /c call.
If this doesn't work, try changing /c above to /c /s per this answer.
YMMV - not tested
Public Sub openEntryFiles()
Dim filePath, shellCommand, agingsEntry, invenEntry As String
filePath = Range("CustomerPath").Value2 & "\files\"
agingsEntry = "agings\entry_EP.bat"
invenEntry = "inven\entry_EP.bat"
shellCommand = """%ProgramFiles(x86)%\TextPad 5\TextPad.exe"" -r -q -u """ & filePath & agingsEntry & """ -u """ & filePath & invenEntry & """"
Debug.Print shellCommand
Shell shellCommand, 0
End Sub
I am trying to write a subroutine that will run a shell command with spaces in the file path. I have done lots of research about using multiple quotes, but I still get a file not found error whenever I run the code. The debug print that is outputted to the Immediate window reads:
"%ProgramFiles(x86)%\TextPad 5\TextPad.exe" -r -q -u "\\ablsgaat002\aclwin\Clients\*****\files\agings\entry_EP.bat" -u "\\ablsgaat002\aclwin\Clients\*****\files\inven\entry_EP.bat"
Copying that string into a shell window works great, however, running it from the Shell command in VBA doesn't work. What am I doing wrong?
Use Environ function to get Special Folders
pathSpecial = Environ("ProgramFiles(x86)")
shellCommand = """" & pathSpecial & "\TextPad 5\TextPad.exe"" -r -q -u """ & filePath & agingsEntry & """ -u """ & filePath & invenEntry & """"
i want my program to open cmd , change directory and then do the command : "copy /B file1 file2 output"
this is what i have at the moment. but all that happens is a cmd window flashes for a second but no file gets created
Dim cmd1 As String
Dim cmd2 As String
cmd1 = "cd " & FolderFromFileName(imagename)
cmd2 = "copy /B " & NameOnlyFromFullPath(imagename) & "+" & "TEMP.txt" & " " & TextBox1.Text
Shell("cmd /c" & " " & cmd1 & " " & cmd2, AppWinStyle.NormalFocus)
please help, thanks :)
Do you really need to have a command prompt appear? You could do all this without a separate process by using the system.io library. If you really need the cmd prompt you can create a process.
Dim NewProcess = New Process
' a new process is created
NewProcess.StartInfo.UseShellExecute = False
' redirect IO
' PVWCmd.StartInfo.RedirectStandardOutput = True
' PVWCmd.StartInfo.RedirectStandardError = True
' PVWCmd.StartInfo.RedirectStandardInput = True
' don't even bring up the console window
NewProcess.StartInfo.CreateNoWindow = False
' executable command line info
NewProcess.StartInfo.FileName = "cmd"
NewProcess.StartInfo.WorkingDirectory = "C:\"
' NewProcess.StartInfo.Arguments = +" > """ + "LogFile.log" + """ 2>&1"
NewProcess.Start()