[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1117
  • Last Modified:

Running different exe file and giving input to that exe file through vb.net

Hai

I am new to vb.net. I am developing one program...
already this program is wriiten in fortran 77. We need to create txt file to input  for this program. now i am developing program in vb.net to create that txt file .

Now i have problem..... that i need to run that exe file and input txt file name through vb.net.
please give your idea...

and at the same time i am creating excel file for store the  input data and output data....
In vb.net program , there are 10 forms .... when each forms i am creating atleast one  excel file.
but some forms i need to create 2 or 3 excel file.for example when different option  button is clicked ,different excel file is to be created.when i do this it takes time to create excel application. In this case what is your suggestion?

finally i am going to combine all excel file to one file.....

Please give your idea to overcome this problem......
0
Nitharsan
Asked:
Nitharsan
  • 8
  • 5
  • 3
  • +1
2 Solutions
 
abelCommented:
These are two very unrelated questions. I suggest you take the part of Excel to the Excel zone, you will have much more luck there. The VB part, we can help you with. In the absence of your app, how would the commandline look like to start your Fortran 77 application with the text file?
0
 
abelCommented:
Suppose, just for illustration purposes, you would open the file in your Fortran77-built application like this on the command prompt:

C:\>myfortranapp.exe -f sometextfile.txt

then you can open that in VB.NET as follows:

Process.Start("myfortranapp.exe", "-f sometextfile.txt")
and the more concerned of the developers will suggest that you call it like this in VB, which is neater and does some more cleaning up for you:

Using proc As Process = Process.Start("myfortranapp.exe", "-f sometextfile.txt")    ' do nothing here, the process will just start End Using

0
 
NitharsanAuthor Commented:
Hai abel

thanks a lot ....
the program written in fortran 77 is already built exe file  with dll files.what we should do is , run that exe file.immediately it will ask txt file name (dos window).I tried the way suggested... while run the exe file at the same time giving the txt file in command line... but it did not work.....
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
NitharsanAuthor Commented:
when i run that exe file  , it will display (dos window) ... and ask txt file name like this...

Enter data file name >>  (then cursor is blinking (in dos window)
0
 
NitharsanAuthor Commented:
Actually this is the way i run that program

C:\3move>3move (exe file name)(immediately it will ask to input file name)
Enter data file name >> ex001.txt (data file name)
0
 
abelCommented:
> while run the exe file at the same time giving the txt file in command line... but it did not work.....

well, that only works if your application has a provision for that. Check the documentation of that application if you can start it with a filename on the commandline.
> run that exe file.immediately it will ask txt file name (dos window)

If it asks for a text file, and you want to "type that in from vb in DOS", then we're going to have to wetten ourselves for a long journey in the depths of cross-process communication and manipulation of 16 bit apps in-memory. That will be close to impossible, though there might be a way. Maybe somebody has already invented an idea?

Is your program public or is it possible for you to share it so that I can test the invocation? You say it has DLLs, do you mean it is actually a win23 application? (DLLs didn't exist in DOS times). If it is, we might have other options.

Not sure how much time you want to invest in this, but if that program does not have a method to automate tasks without user interaction, we're gonna have it hard...

-- Abel --
0
 
NitharsanAuthor Commented:
Unfortunately  this program is private....i cannot share it....
anyway i talk with my supervisor about sharing this program.....

this program is written by using Microsoft Fortran powerstation (32 bit).... i just attached doc file to show how it run.
as you said it has not provision for giving file name at the same line.....



Nitha


3DMOVE-FILES.doc
0
 
NitharsanAuthor Commented:
Hai  abel

any solution for this problem?

0
 
abelCommented:
Please, don't push, I'm a bit allergic to that. We're all volunteers here and I do sleep occasionally (yes, I know, it happens)... I try to attend back to questions promptly, but my free time is only so large...

Like I said in an earlier post, this may be nasty to workaround. Luckily, your fortran program does not use a graphical dos interface, which makes matters easier. Googling gave a PushKeys dll which would be handy to use, but I couldn't find any download of it anymore.

Here's an example of a way it works with WinWedge (I do not know that program), but the technique might also work from VB: http://www.taltech.com/support/sw_tricks/sending.htm

A total programmable solution is here: http://binaryworld.net/Main/CodeDetail.aspx?CodeId=1485 (VB6 code, but easy to read, which seems to really manage to send keys to a DOS program. The code is in VB6, which needs a little translation. If you create a VB6 program with an old version of VS, you can let the new VS version translate it for you automatically.

This C++ program also sends keys to DOS applications (even though the article doesn't mention it, it is mentioned by the application and by some commenters): http://www.codeproject.com/KB/cpp/sendkeys_cpp_Article.aspx

As you can see: it can be done, but, as esp. the VB6 code shows, it is quite daunting. My advice would be to use some of this ready made code that suits you. Unfortunately, there's no ready made C# or VB.NET solution, but you can wrap either the C++ DLL, or translate the VB6 code.

-- Abel --
0
 
dcesariCommented:
If you have the chance to modify and recompile your fortran program, then it would be simple to switch from getting a file name interactively to getting that file name from the command line, probably you will have some fortran lines like these:

       PRINT*,'Enter data file name >> '
       READ*,A

just try to change these lines in

       CALL getarg(1, A)

and recompile, this will mean that the file name will be received from the command line and not interactively, so that you will be able to use the previous suggestion (without -f in this case):

Process.Start("myfortranapp.exe", "sometextfile.txt")

This at least works with most of the Unix fortran compilers, I do not know in windows, but there should be some getarg subroutine in M$ fortran too.
0
 
dcesariCommented:
Any progress?

In general, if file name in fortran is read interactively from keyboard input, this is equivalent, in msdos batch file, to the following:

myfortranapp.exe < sometextfile.txt

where sometextfile.txt contains a line with the desired name; I don't know how to do input redirection in VB, but maybe someone (abel?) can help on that?
0
 
nirojexpertCommented:
can you try using the sendkeys method.
run the program. have the focus on it. and the using sendkeys, send the name of the file.
 
0
 
abelCommented:
Sendkeys won't work, it is a DOS app (see my comments and the ones from the OP).

> I don't know how to do input redirection in VB, but maybe someone (abel?) can help on that?

yes, i can ;)
but this is not a comment from the OP, is it? And it seems that the FORTRAN application was not made with redirection in mind. However, input redirection of DOS programs requires a bit of extra effort. In general, see the links in my earlier comments, which allow you to send keystrokes. There was recently another question I answered that showed capturing the stdin/out/err.
0
 
dcesariCommented:
> but this is not a comment from the OP, is it?
No, it's not.

> And it seems that the FORTRAN application was not made with redirection in mind.
Well a plain FORTRAN READ instruction, as the one that seems to do the program indicated by the author, should read from standard input stream, so even though it is not designed for an interactive use, it should work anyway with input redirection from a file with the proper contents.

Anyway, let's wait for OP feedback.
0
 
abelCommented:
good point. Definitely worth a try and it would save loads of effort :)
0
 
nirojexpertCommented:

i tried with sendkeys but it does not seem to work.
can you try using the api sendMessage to send text/commands to the window.
 
0
 
abelCommented:
@nirojexpert: indded it doesn't work, and SendMessage won't work either. See my earlier comments (it is worthwhile to see what's already suggested, really).

It is not possible with the regular API. It is not that hard with other messages either, just a bit of work. What you need is keybd_event and to translate the keys to the correct DOS/OEM equivalents using OemKeyScan, CharToOem, VkKeyScan and MapVirtualKey. The links I showed explain this.
0
 
abelCommented:
@Dhaest: this question has received extensive coverage, I even put it to my KB because of the quality of the links explaining how to send keystrokes to a DOS window. Also, the asker received answers on how to change the original Fortran code to allow for redirection.

Suggestion: points split between http:#24222634 (abel, extensive answer containing all necessary details to send keystrokes to DOS windows or do input redirect) and http:#24223076 (nirojexpert, explaining how to do it from within Fortran).
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 8
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now