nightwish

Hi All,

This is a tricky situation...

I wrote an application that filters through a input text file to remove any " and add new headings etc. It contains 2 inout text boxes for the 2 inout text files and 2 output files...

After specifying the location of both an clicking on the filter button it filters and saves the files.

My question if if you can run this program form a dos batch file to automate the process.

i.e. normally what would happen is you could do something like c:\filter.exe -title -filename1 -filename2 -output1 - output2

But how do you encorporate this into the program

Thanks

This is the code for converting the files:

Me.Cursor = Cursors.WaitCursor

tspDate.Text = "Converting..."

Dim tlinks As String = "t links"

Dim ls As String = My.Computer.FileSystem.ReadAllText(txtInputLink.Text.ToString)

ls = ls.Replace("""", "")

My.Computer.FileSystem.WriteAllText(txtOutputLink.Text.ToString, "c" & vbCrLf & "c " & txtTitle.Text & " (" & txtInitials.Text & ")" & vbCrLf & "c" & vbCrLf & "c " & "Date Created: " & txtDate.Text & vbCrLf & tlinks & vbCrLf & ls, False)

Dim tnodes As String = "t nodes"

Dim ns As String = My.Computer.FileSystem.ReadAllText(txtInputNode.Text.ToString)

ns = ns.Replace("""", "")

My.Computer.FileSystem.WriteAllText(txtOutputNode.Text.ToString, "c" & vbCrLf & "c " & txtTitle.Text & " (" & txtInitials.Text & ")" & vbCrLf & "c" & vbCrLf & "c " & "Date Created: " & txtDate.Text & vbCrLf & tlinks & vbCrLf & ns, False)

Me.Cursor = Cursors.Default

tspDate.Text = "Date: " & My.Computer.Clock.LocalTime.Day.ToString & "-" & My.Computer.Clock.LocalTime.Month.ToString & "-" & My.Computer.Clock.LocalTime.Year.ToString




Re: Visual Basic Express Edition Running a program in conjunction with a batch file

averge joe

So you wan't to run a .exe from a batch file whats the purpose of that I can get how to do that if you tell me thats what you want to do



Re: Visual Basic Express Edition Running a program in conjunction with a batch file

nightwish

Yes, i want to run a .exe from a batch file.

The reason for this is, that i have a script set up in MapInfo (This will call the .bat file). This chops and changes the inputs around and then eventually dumps it into a text file. This is then read in by my program but using the browse buttons etc. What my plan is to have the program developed and have the option of using a batch file so that you can interactivelly call the program from within MapInfo(using the bat file) without having to do it manually, as per my last post the bat file will contain something like "C:\application.exe -title..."

Thanks






Re: Visual Basic Express Edition Running a program in conjunction with a batch file

spotty

You can use the command line arguments in your application.

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'//Get The command Line Arguments
If My.Application.CommandLineArgs.Count > 0 Then
For Each s As String In My.Application.CommandLineArgs
Next
Else
End If
End Sub
End Class


Doing something like this allows you to write you application so that if you provide it with command line arguments can determine there contents and run a process - if you dont provide any then you can run interactively....

Ultimately this determination will be made when the form load event fires.

Then you have to make your application process the command line arguments and run the process without user involvement. To me it sounds like a console application type of process but if you want to implement as a windows application then its pretty easy.





Re: Visual Basic Express Edition Running a program in conjunction with a batch file

nightwish

Well, it's pretty much a compination of both. You should be able to either load the program by double clicking the .exe or if you do it as part of a script  (batch file) then you should specify your arguments adn it should do the things without opening the GUI and do it via a console window.

Thanks

 






Re: Visual Basic Express Edition Running a program in conjunction with a batch file

spotty

A really simple program which can work interatively or batch. My suggestion start with a very small simple application like this - understand how if work and why it works in interactive and batch modes. Then once you understand this apply it to you application which is probably more complex.

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'//Get The command Line Arguments
If My.Application.CommandLineArgs.Count > 0 Then
Dim s As String = My.Application.CommandLineArgs(1)
ProcessFunction(s)
Me.Close()
Else
'//Interactive Mode
End If
End Sub

Sub ProcessFunction(ByVal x As String)
My.Computer.FileSystem.WriteAllText("C:\test.txt", x, True)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ProcessFunction(TextBox1.Text)
End Sub

Private Sb Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class





Re: Visual Basic Express Edition Running a program in conjunction with a batch file

nightwish

This is the code that i currently have. I found it easier to code it this way, but it still doen't work. I has something to do woth the Strings... Please help.

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Try

Dim pn As String
Dim pt As String
Dim initials As String
Dim datep As String
Dim il As String
Dim ino As String
Dim ol As String
Dim ono As String

Select Case LCase(Command$()) 'convert command to lowercase

Case "/i" & " /" & pn & " /" & pt & " /" & initials & " /" & datep & " /" & il & " /" & ino & " /" & ol & " /" & ono

Dim t As String = My.Computer.FileSystem.ReadAllText(il.ToString)
t = t.Replace("""", "")
My.Computer.FileSystem.WriteAllText(ol.ToString, "c" & vbCrLf & "c " & pn & " - " & pt & " (" & initials & ")" & vbCrLf & "c" & vbCrLf & "c " & "Date Created: " & datep & vbCrLf & "t links" & vbCrLf & t, False)

Dim s As String = My.Computer.FileSystem.ReadAllText(ino.ToString)
s = s.Replace("""", "")
My.Computer.FileSystem.WriteAllText(ono.ToString, "c" & vbCrLf & "c " & pn & " - " & pt & " (" & initials & ")" & vbCrLf & "c" & vbCrLf & "c " & "Date Created: " & datep & vbCrLf & "t nodes" & vbCrLf & s, False)

Case "/ ", "/help"

Process.Start("c:\help.hlp")
End

Case Else

End Select

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub






Re: Visual Basic Express Edition Running a program in conjunction with a batch file

spotty

Have you placed a breakpoint on the code and actually tried to debug it.

I would hazard a guess that you are not processign the command line correctly and it may not match either of the case situations. Stick a messagebox in the Case Else condition and see if it is executing in this part of the code.

I can't tell you whats wrong as its based upon the values you are passing to the executable. The code skeleton I provide worked and if you use that and take things in small steps and debug your code at each step you should be able to resolve your own problem.





Re: Visual Basic Express Edition Running a program in conjunction with a batch file

nightwish

I have managed to get the application running woth various command line etc.I used your example.

I still have a problem with specifying the inputs...

i.e:

c:\application.exe /i (Now loads the application with the command line, but i need to know how to do inout files.)

The idea is to have something like: c:\application.exe /i -Project_Title -c:\input_file.txt -c:\output_file.txt

Where /i loads the command line and then how do you read in the other paramters

I hnow how to do al the rest with the process following etc.

Thanks






Re: Visual Basic Express Edition Running a program in conjunction with a batch file

spotty

Firstly I'd try

Process.start ("C:\Application.exe," /i -Project_Title -c:\input_file.txt -c:\output_file.txt")

Does that work....