How to send Multiline sms using gnokii with vb.net - vb.net

dear all im tried to send multiline sms using gnikii but it fails
Dim xCmd As String
xCmd = "cmd.exe /c echo " & txtBody.Text & " | c:\sms\gnokii.exe --sendsms 0771234567 2> test.txt"
Shell(xCmd)
Please help me

You can split your text on vbCrLf and add echo in front so you end up with this cmdline instead
cmd.exe /c lineOne echo line2 | c:\sms\gnokii.exe --sendsms 0771234567 2> test.txt
code wise you can do it like this:
Dim sString As String
Dim aLines As String()
Dim xCmd As String
sString = "lineOne" & vbCrLf & "line2"
aLines = sString.Split(vbCrLf)
sString = Join(aLines," echo")
xCmd = "cmd.exe /c " & sString & " | c:\sms\gnokii.exe --sendsms 0771234567 2> test.txt"
Shell(xCmd)

Related

Printing to Brother PT-D600 from MS Access Using VBA

I am trying to print a Serial Number to a Brother PT-D600 printer whenever an MS access form is submitted.
This is my current script.
Public Sub PrintLabel_Click(ByVal printStatement As String)
On Error GoTo ErrorHandler
Dim labelmakerPath As String
labelmakerPath = "C:\Program Files (x86)\Brother\Ptedit54\ptedit54.exe"
Dim labelData As String
labelData = printStatement
Dim labelPath As String
labelPath = "C:\Users\Username\Documents\My Labels\AutoLabel.lbx"
Dim labelCommand As String
labelCommand = """" & labelmakerPath & """" & " /X """ & labelData & """ """ & labelPath & """"
Dim success As Integer
success = Shell(labelCommand, vbNormalFocus)
If success = 0 Then
MsgBox "Error: Unable to run command: " & labelCommand, vbExclamation, "Error"
End If
Exit Sub
ErrorHandler:
MsgBox "An error occurred: " & Err.Description, vbExclamation, "Error"
End Sub
While trying to debug, I've tried to use the following python script to print directly from the command line
import subprocess
serialNumber = "20230219"
labelText = "1234567"
printerName = "Brother PT-D600"
printCommand = f'ptouch-printer -n "{printerName}" -l "24mm" -t "test label" -i "ABC" -s "{serialNumber}" -b "1" -q "1" "{labelText}"'
# Print the label
try:
subprocess.run(printCommand, shell=True, check=True)
print("Label printed successfully")
except subprocess.CalledProcessError as e:
print(f"Printing label failed: {e}")
However, it doesn't seem like ptouch-printer is available anymore?

Different results for exit conditions in process call

As a small part of a project, I'm calling ffmpeg to convert a video - I worked from an old example that used some of the output to create a progress bar, which was hanging. Code below:
[initiation code common to both examples]
Dim inputFile, outputFile As String, myProcess As New Process
Dim psiProcInfo As New ProcessStartInfo, ffreader As StreamReader
inputFile = "C:\Users\mklefass\Downloads\Video 2017-08-16 21.01.39.mov"
outputFile = "C:\Users\mklefass\Downloads\tmp2\Output"
psiProcInfo.FileName = Application.StartupPath + "\ffmpeg.exe" 'Location Of FFMPEG.EXE
psiProcInfo.Arguments = " -i " & Chr(34) & inputFile & Chr(34) & " -vf fps=5 " & Chr(34) & outputFile & "%d.jpg" & Chr(34) 'start ffmpeg with command strFFCMD string
psiProcInfo.UseShellExecute = False 'use the shell execute command we always want no
psiProcInfo.WindowStyle = ProcessWindowStyle.Hidden 'hide the ffmpeg process window
psiProcInfo.RedirectStandardError = True 'Redirect the error out so we can read it
psiProcInfo.RedirectStandardOutput = True 'Redirect the standard out so we can read it
psiProcInfo.CreateNoWindow = True
[bit that changes]
myProcess.Start()
ffreader = myProcess.StandardError
Do
Try
If Not myProcess.HasExited Then
'Debug.WriteLine(ffreader.ReadLine)
End If
Catch
If Not myProcess.HasExited Then
MsgBox("Something went wrong")
End If
End Try
Loop Until myProcess.HasExited
MsgBox("done")
I then found another example that just called the executable and then continued when it was done - as below:
[same initialisation]
Debug.WriteLine("Starting...")
myProcess.Start()
strOutput = myProcess.StandardError.ReadToEnd
myProcess.WaitForExit()
myProcess.Close()
Debug.Write(strOutput)
MsgBox("done")
The second approach worked perfectly... What's different about the "exit state" that Process.HasExited and Process.WaitForExit look for?

& operator string error with string of arguments to processStartInfo

I need to pass a string into the ProcessStartInfo for ffmpeg so that I can call the dim.Argument and have it append the strings and variables from code as I parse through the files.
I have the current filename.mp3 that the code sees in movedFileInfo but it won't allow me to append it to the string using & operators... help?
I know there may be one other way to do this utilizing the ffmpeg command in separate function to simply loop through a directory using "for" but I've not found a successful command for running my ffmpeg.exe nor the ffprompt in windows. I also need to append a carriage return when I write to merge.txt but can't find an example... I'm new to vba.
These commands work but vba is complaining about the & operator in my string with the error The operator '&' is not defined for types 'String' and 'System.IO.FileInfo'.
So what I understand is that the string I'm passing into psi.Arguments doesn't like the fact that I'm sending it a string and a variable appended using the & operator... do I simply use a comma or how do I append the variable movedFileInfo to ffmpeg -i? psi is defined above as ProcessStartInfo... so I'm not sure what types vb recognizes for it... I haven't found info on ProcessStartInfo to kick off my ffmpeg exe.
See code below:
Imports System
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'videos are from SD card always on I:\Private\AVCHD\BDMV\STREAM\
'store files to RAID drives in folders structured as :
' F:\BUILD\FLIGHT#\CAM#\<TAIL_NUMBER>_FLT_<FLT_NUMBER>_UTC_<START_UTC_TIME>_CAM_<CAM_NUMBER>.MTS
'set base dir as directory F:\
Dim dir As String = "C:\"
Dim video_card_dir As String = "C:\1bak\" '"I:\Private\AVCHD\BDMV\STREAM\"
Directory.SetCurrentDirectory(dir)
Dim new_flightnum_directory = dir & Me.BUILD.Text & "\" & FLT.Text & "\"
'establish new video dir> F: \ BUILD \ FLIGHT # \ CAM # \
Dim new_video_directory = dir & Me.BUILD.Text & "\" & FLT.Text & "\" & Me.CAM.Text & "\"
'establish new filename to rename the video file
' TAIL # FLT #
Dim new_filename As String = TAIL.Text & "_" & FLT.Text & "_" & UTC.Text & "_" & CAM.Text
Dim ffmpeg As String = "C:\ffmpeg\bin\ffmpeg.exe"
'****FFMPEG required variables
Dim psi As ProcessStartInfo = New ProcessStartInfo("C:\ffmpeg\bin\ffmpeg.exe")
Dim proc As Process = Process.Start(psi)
psi.UseShellExecute = True
psi.CreateNoWindow = True
'****end FFMPEG required variables
'!!!!!!!!!!!!!!!!!!!!!!!!!!!need to add the processing below to the IF statement aboev so that if the folders exist, the video processing doesn't attempt to run on existing files
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~START - MOVE THIS DOWN BELOW CREATION OF FILE STRUCTURE WHEN DOEN DEBUGGING************
'***START MOVING the files from the card to the new directory****
For Each foundFile As String In My.Computer.FileSystem.GetFiles(video_card_dir, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.MTS")
Dim foundFileInfo As New System.IO.FileInfo(foundFile)
My.Computer.FileSystem.MoveFile(foundFile, new_video_directory & foundFileInfo.Name)
Next
For Each foundFile As String In My.Computer.FileSystem.GetFiles(video_card_dir, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.MTS")
Dim movedFileInfo As New System.IO.FileInfo(foundFile)
psi.Arguments = "ffmpeg -i " & movedFileInfo & " -vcodec -c libx264 " & movedFileInfo & ".mp4"
psi.ToString()
'proc = Process.Start(psi)
'***convert each MTS file in the new directory to MP4****
'Writes filenames to merge.txt as " path\to\merge.txt , 'file ' F:\path\to\ file1 .MP4 '" so that ffmpeg can merge, then rename
'My.Computer.FileSystem.WriteAllText(new_video_directory & "merge.txt", "file '" & movedFileInfo & ".mp4'" & vbCrLf, True)
'>>>>need to add carriage return to text file
'NOW CAPTURE FILENAMES OF MP4 and MERGE INTO 1 MP4 FILE
' merge all F:\path\to\merge.txt to merge the files & merge them
'psi.Arguments = "ffmpeg -f concat -i " & new_video_directory & "merge.txt -c copy " & new_filename & ".mp4"
proc = Process.Start(psi)
Next
'***END MERGE FILES***
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~* END - MOVE
'***START CREATE STORAGE DIRECTORY STRUCTURE ***
'Verify if the build # directory exists?
If My.Computer.FileSystem.DirectoryExists(dir & Me.BUILD.Text) Then
MessageBox.Show("The build directory exists, moving on to create subdirectories")
Else
Try
'create the new directory F:\ build \ FLIGHT #
My.Computer.FileSystem.CreateDirectory(dir & Me.BUILD.Text)
MessageBox.Show("The build directory" & dir & Me.BUILD.Text & " was created.")
Catch ex As Exception
MessageBox.Show("Doh! The build directory could not be created! Error: " & ex.Message, "Error creating directory.", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
'verify if the flight num directory exists - or create it
If My.Computer.FileSystem.DirectoryExists(new_flightnum_directory) Then
MessageBox.Show("The flight # folder already exists! Check that you have the right Flight #.")
Else
Try
'create the new directory F:\ BUILD \ FLIGHT #
My.Computer.FileSystem.CreateDirectory(new_flightnum_directory)
'Now create new subDirectories
My.Computer.FileSystem.CreateDirectory(new_video_directory)
MessageBox.Show("The new flight directory & video CAM subdirectories have been created! The videos will be moved and files converted now which will take some time.")
Catch ex As Exception
MessageBox.Show("Doh! The flight num or CAM directory could not be created! Error: " & ex.Message, "Error creating directory.", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
'***END CREATE STORAGE DIRECTORY STRUCTURE ***
MessageBox.Show("new merged video file has been created in " & dir & Me.BUILD.Text & "\" & Me.CAM.Text)
End Sub
End Class
The problem is that the & operator in VB is used only to concatenate System.String objects. It's stricter than using + to concatenate. You can't use it to concatenate a String and a System.IO.FileInfo object together. What you want is to get the file name from the FileInfo object. It has an attribute, FileInfo.FullName which will return the full path of the file as a String - from the documentation.
Try instead:
For Each foundFile As String In My.Computer.FileSystem.GetFiles(video_card_dir, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.MTS")
Dim movedFileInfo As New System.IO.FileInfo(foundFile)
psi.Arguments = "ffmpeg -i " & movedFileInfo.FullName & " -vcodec -c libx264 " & movedFileInfo.FullName & ".mp4"
psi.ToString()
proc = Process.Start(psi)
Next
If you want to replace the .mts extension with .mp4, instead of simply appending .mp4 as this code does, please see this question.

vb.net How to pass a string with spaces to the command line

I am trying to call an external program using Process:
Dim strExe As String = "E:\Projects\Common Files\mktorrent.exe"
Dim p As New Process
Dim pinfo As New ProcessStartInfo
pinfo.UseShellExecute = False
pinfo.RedirectStandardOutput = True
pinfo.Arguments = " -a http://blah.com/announce.php -l " & FileSizeMarker & " " & fn
pinfo.FileName = strExe
pinfo.WorkingDirectory = fn.Substring(0, fn.LastIndexOf("\"))
pinfo.WindowStyle = ProcessWindowStyle.Normal
pinfo.CreateNoWindow = True
p.StartInfo = pinfo
p.Start()
The problem is with the filename (variable fn above). If it has spaces, the command chokes - without spaces, it works fine. I have tried adding 1, 2 or3 quotes, like this:
fn = Chr(34) & Chr(34) & Chr(34) & fn & Chr(34) & Chr(34) & Chr(34)
and also
fn = "\") & Chr(34) & fn & "\"& Chr(34)
and many other combinations, but it still gives me an error. Any thoughts on how I can get this to work?
TIA
It's really an old - but unsolved - problem.
My 2 cents of contribution.
Use CHR(34) before-and-after the string, delimiting it like:
Arg = "Name=" & chr(34) & "John Doe da Silva" & chr(34)
Just it!
Please check the below link, its in C#, may be its helpful to you
Word command-line-arguments space issues
Windows does not provide a common way of keeping arguments with spaces as single arguments. However there are a number of relatively common standards that you've tried.
So it comes down to either determining what argument processing mktorrent.exe uses or, as you're trying to pass a filename, using "MSDOS" 8.3 format for the path which will have no spaces.
For the latter, this answer points to the Win32API GetShortPathName.
Of course, 8.3 filenames can be disabled with modern Windows (all Windows NT-based systems I believe -- not that it often is). So your only full solution is to determine what argument processing mktorrent supplies.
Since your comment suggesting the quotes are not being passed through I confirmed I see 'testing' 'testing' '1 2 3' in the MsgBox output of this vbscript:
Option Explicit
Dim arg
Dim line
For Each arg in WScript.Arguments
line = line & " '" & arg & "'"
Next
MsgBox Trim(line)
when executed using:
Dim strExe As String = "C:\Windows\System32\wscript.exe"
Dim p As New Process
Dim pinfo As New ProcessStartInfo
pinfo.UseShellExecute = False
pinfo.RedirectStandardOutput = True
pinfo.Arguments = " G:\Utils\Arguments.vbs testing ""testing"" ""1 2 3"""
pinfo.FileName = strExe
pinfo.WorkingDirectory = "G:\Utils"
pinfo.WindowStyle = ProcessWindowStyle.Normal
pinfo.CreateNoWindow = True
p.StartInfo = pinfo
p.Start()
So wscript is seeing the quotes and is accumulating three arguments for the script.
BTW I just noticed your example attempts at getting quotes around the filename modify the fn variable. Did you cater for this with the .WorkingDirectory line, which should be using the unmodified filename?
This allows me to pass spaces to cmd. Hours of research turned up nothing; this thread came up constantly, hopefully this will help someone else.
Dim startprgm As New ProcessStartInfo("cmd.exe", "/C """"C:\Program Files (x86)\Folder\File""""" + strArguments)
note that the 4 double quotes lead the path, this part is important. leading the argument (/C) with 5 quotes doesn't work, but the trailing five can be divided into 4 and 1; and structured as such:
Dim startprgm As New ProcessStartInfo("cmd.exe", "/C """"C:\Program Files (x86)""""\Folder\File" + strArguments)
If you open cmd.exe and just send a command, you just need the first quote on the path (it doesn't need to be closed) but VB needs the trailing ones to "close" the quotes out.
best of luck, guys.
This WORKS:
Dim current_path, current_rulename, cmd1 as STRING
current_path = "C:\this folder\file name.exe"
current_rulename = "file name.exe"
cmd1 = "netsh advfirewall firewall add rule name = """ + current_rulename + """ dir = in action = block program = """ + current_path + """"
cmd1 &= " & "
cmd1 &= "netsh advfirewall firewall add rule name = """ + current_rulename + """ dir = out action = block program = """ + current_path + """"
cmd1 &= " & pause"
Process.Start("cmd", "/c " + cmd1)
Basically, the variables with spaces need to be enclosed like this:
""" + string_with_spaces + """
Broken into parts:
cmd1 =
"
netsh advfirewall firewall add rule name =
""" + current_rulename + """
dir=in action=block
program=
""" + current_path + """
"
This code joins two separate commands that use STRINGS with spaces.
Be simple:
Process.Start("c:\Your exe file", """" & "string with space" & """")

vb.net problem running a command

the following runapplication won't work
Private Sub RunApplication(ByVal ProgName As String)
// String of text as a command to execute with the command line interpreter
Dim strApplication As String = "cmd.exe/c"
Dim ProcessID As Integer
strApplication = strApplication & " " & ProgName & " > C:\tool.tmp"
// Execute the command but hide it from the user
Shell(strApplication, AppWinStyle.Hide, True)
// View the Output in notepad.exe
ProcessID = Shell("notepad.exe C:\tool.tmp", AppWinStyle.NormalFocus)
AppActivate(ProcessID)
any suggestions would be gratefully appreciated
Put a space "cmd.exe/c" should be "cmd.exe /c"