none
Starting external app causes File Not Found error - why? File with path is correct RRS feed

  • Question

  • Hi!

    I'm rewriting older app from VB6 to VB.NET.

    I selected NETfw 2.0.

    When user selects file then select option and after pushes button it tries to start external Java app by:

    RunString = "java -cp " & path & argument
    Shell(RunString, AppWinStyle.NormalFocus)

    example of RunString:

    java -cp "D:\emulatory\z64k\z128k.jar" model.vic20.StartVIC20

    tried was also without "java -cp"

    tried also without quotes in path

    but always reports error:

    System.IO.FileNotFoundException: 'File not found.'

    Why it does it? In VB6 near identical start causes no any problem...

    Miro

    Monday, June 19, 2017 1:31 PM

Answers

  • So, I was desperate and downloaded and installed new Java... and success - it works.

    I used simple Shell command.

    Please forgive me that I wasted your time.

    Miro

    • Marked as answer by mksft Wednesday, June 21, 2017 11:39 AM
    Wednesday, June 21, 2017 11:38 AM

All replies

  • Some things come to me to try:

    look at the exception detail - what file is not found ?
    If it is "java" - instead of just "java" - use the full path to the java executable

    Copy the Runstring and paste it into a command prompt, see if that also fails.
    If that fails, modify the command until it works and then adjust how it is assembled in your code to match. 

    Use Process.Start(ProcessStartInfo) - Reference is here.

    Monday, June 19, 2017 2:33 PM
  • I tried to start it from cmdline.

    You're true, JAVA needs path.

    I started JAR directly and it works. Then I changed RunString by removing Java prefix, but helped not - same error no matter if quoted path.

    I'll try Process.StartInfo, but later, now I must to go, will reply.

    Miro

    Monday, June 19, 2017 3:32 PM
  • This comes not from the code you gave us. 

    System.IO.FileNotFoundException: 'File not found.'

    It means that you did use System.IO and there is nothing about that in the by you supplied code.


    Success
    Cor


    Monday, June 19, 2017 4:58 PM
  • I used in code topmost

    Imports System.IO

    Needs it anything more?

    Miro

    Monday, June 19, 2017 5:40 PM
  • I think I misunderstood it, try the path likewise this. 

    """D:\emulatory\z64k\z128k.jar"""
    That embeds the path in on both side one quote.


    Success
    Cor


    Monday, June 19, 2017 6:11 PM
  • I know that problem, but really is path with parameters created:

    chr(34) & path & chr(34) & parameter

    - parameter begins with space to avoid merge to previous character.

    Miro

    Monday, June 19, 2017 6:18 PM
  • I know that problem, but really is path with parameters created:

    chr(34) & path & chr(34) & parameter

    - parameter begins with space to avoid merge to previous character.

    Miro

    Why do you not show the real code, it is now simply a puzzle. 

    If you do that use that button with the <> right from the HTML button. 


    Success
    Cor

    Monday, June 19, 2017 8:14 PM
  • cesta = D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar
    
        Private Sub GO_Click(sender As Object, e As EventArgs) Handles GO.Click
    
            ' On Error GoTo Failure
    
            If C128.Checked = True Then Volanie = " model.commodore128.StartC128"
            If C64.Checked = True Then Volanie = " model.commodore64.StartC64"
            If VIC20.Checked = True Then Volanie = " model.vic20.StartVIC20"
            If A2600.Checked = True Then Volanie = " model.atari2600.Start_Atari2600"
    
            Javapp = "java - cp "
    
            QCesta = Chr(34) & Cesta & Chr(34)
    
            RunString = Cesta & Volanie
    
            Shell(RunString, AppWinStyle.NormalFocus)
            'Process.Start(RunString)
            End
    
    Failure:
            MsgBox("Process failed")
            End
        End Sub

    This is code of click button subroutine.

    Miro

    Monday, June 19, 2017 10:18 PM
  • This is code of click button subroutine.

    Show the exact command line that you want to execute for one of those examples (eg, C128.Checked).  Currently your code does not use the values that you created in QCesta or Javapp, so the run command is quite different than what you originally posted.

    • Edited by Acamar Monday, June 19, 2017 10:32 PM sp
    Monday, June 19, 2017 10:31 PM
  • getting Cesta variable string:
    Cesta = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Mirkosoft\Z-Menu", "Path", 0).ToString
    
    reg. key value content:
    D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar
    
    Javapp = "java - cp "
    
    QCesta = Chr(34) & Cesta & Chr(34)	>	Chr(34) & "D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar" & Chr(34)
    
    Volanie = " model.commodore128.StartC128"
    
    tested were:
    
    RunString = Javapp & Cesta & Volanie	>	'java - cp D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar model.commodore128.StartC128'
    
    RunString = Javapp & QCesta & Volanie	>	'java - cp "D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar" model.commodore128.StartC128'
    
    RunString = Cesta & Volanie		>	'D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar model.commodore128.StartC128'
    
    RunString = QCesta & Volanie		>	'"D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar" model.commodore128.StartC128'
    
    ' = Runstring single quote defines whole string
    These were tested - each beginning Javapp were not working in cmdline.
    Monday, June 19, 2017 11:02 PM
  • These were tested - each beginning Javapp were not working in cmdline.

    So if those last two work at a command prompt, then what happens when you use them in your code?  I suspect that 

    D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar model.commodore128.StartC128

    won't work for Process.Start as the command line parses keyboard entry slightly differently: that last one looks best to me.

    Simplify your code by using the command as a single string literal - don't try to create it from the substrings. Use Process.Start - not Shell.  If that doesn't work try using a Process object and specifying the parts of the command (including the start folder) separately.

    You can probably get that first form to work if your options indicate jar not class:

    java -jar "D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar" model.commodore128.StartC128

    but for that sort of question you should ask in a java forum.

    Tuesday, June 20, 2017 12:02 AM
  • "I started JAR directly and it works"

    Using what exact command ?

    Tuesday, June 20, 2017 12:11 AM
  • Dim startInfo As New ProcessStartInfo(QCesta)
    startInfo.WindowStyle = ProcessWindowStyle.Normal
    
    startInfo.Arguments = Volanie
    
    Process.Start(startInfo)

    This starts default emulator - Commodore 128 - no matter of arguments.

    What a special format has/processing argument in Process.Start ?

    'Cause when I use RunString it reports again the same error report.

    Miro

    Tuesday, June 20, 2017 12:21 AM
  • 'Cause when I use RunString it reports again the same error report.

    Then don't use RunString.

    The process object can use a StartInfo object that exactly specifies what you want to do.  This includes the argument and the windowstyle, which you have. It requires the command (Filename), which you have overlooked.

    Optional additional items include the working directory, which might be relevant, depending on the application you are starting. See:
    https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo(v=vs.110).aspx

    Simplify your code by using the command as a single string literal - don't try to create it from the substrings. Posting a line of code like
        startInfo.Arguments = Volanie

    serves no purpose because no-one knows what the value is.

    Tuesday, June 20, 2017 1:04 AM
  • Dim startInfo As New ProcessStartInfo(QCesta)
    startInfo.WindowStyle = ProcessWindowStyle.Normal
    
    startInfo.Arguments = Volanie
    
    Process.Start(startInfo)

    This starts default emulator - Commodore 128 - no matter of arguments.

    What a special format has/processing argument in Process.Start ?

    'Cause when I use RunString it reports again the same error report.

    Miro

    The startinfo arguments is a string using a space to separate each argument, if an argument has a space in it it needs to be in quotes, so yours should something like:

    Startinfo.command = the java runtime (Full path if necessary)

    StartInfo.Arguments = "-cp or -jar" & " " & chr(34) & D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar & chr(34) & " " & "model.commodore128.StartC128"

    Everything you need is in the link that Acamar posted.

    Tuesday, June 20, 2017 5:22 AM
  • Here are results:

    Cesta = D:\Commodore\Commodore 128\VICE NEW\Z64K\Z128.jar
    
    VB6
    ---
    Volanie = "java -cp " & Chr(34) & Cesta & Chr(34) & " model.vic20.StartVIC20"
    
    Shell (Volanie)
    
    VB.NET
    ------
    Javapp = "java -cp" & Chr(32)
    
    Volanie = Javapp & Cesta & Chr(32) & "model.commodore128.StartC128"
    
    Shell(Volanie)			; outputs error: System.IO.FileNotFoundException: 'File not found.'
    
    Process.Start(Volanie)		; outputs error: System.ComponentModel.Win32Exception: 'The system cannot find the file specified'
    
    Process.Start(Cesta, Volanie)	; works like no parameter

    Purpose of program is to select emulated machine...

    When it processes no argument, it's useless.

    Look into code - VB6 version works simply - why works not VB.NET version?

    Tuesday, June 20, 2017 5:35 PM
  • I'm desperate.

    In VB6 is possible to work, but it's old PL, how to get it work in VB.NET?

    Miro

    Tuesday, June 20, 2017 8:38 PM
  • I got work Shell - calling command line.

    Now works this - but it looks like no any argument entered:

            QCesta = Chr(34) & Cesta & Chr(34)
    
            If C128.Checked = True Then Volanie = QCesta & " " & "model.commodore128.StartC128"
            If C64.Checked = True Then Volanie = QCesta & " " & "model.commodore64.StartC64"
            If VIC20.Checked = True Then Volanie = QCesta & " " & "model.vic20.StartVIC20"
            If A2600.Checked = True Then Volanie = QCesta & " " & "model.atari2600.Start_Atari2600"
    
            Dim RunString As String = "cmd /c " & Volanie
    
            Shell(RunString, AppWinStyle.NormalFocus)

    What is there wrong with argument? Is it problem of calling Java application?

    'Cause near same code works in VB6 - with calling Java app by "java -cp":

        If C128.Value = True Then Volanie = "java -cp " & Chr(34) & Cesta & Chr(34) & " model.commodore128.StartC128"
        If C64.Value = True Then Volanie = "java -cp " & Chr(34) & Cesta & Chr(34) & " model.commodore64.StartC64"
        If VIC20.Value = True Then Volanie = "java -cp " & Chr(34) & Cesta & Chr(34) & " model.vic20.StartVIC20"
        If A2600.Value = True Then Volanie = "java -cp " & Chr(34) & Cesta & Chr(34) & " model.atari2600.Start_Atari2600"
        
        Shell (Volanie)

    It works in my computer (VB6 version), but in command line calling Java by "java -cp" reports failure...

    Miro


    • Edited by mksft Tuesday, June 20, 2017 9:05 PM
    Tuesday, June 20, 2017 9:04 PM
  • It works in my computer (VB6 version), but in command line calling Java by "java -cp" reports failure.

    You have ignored the suggestions that were provided:
    - Use a Startinfo object and Process.Start

    - Create a command and an argument for the StartInfo object

    - Create both the command and argument as single string literals, so you can see exactly what is being executed. You have to be able to prove that exactly the same string is being used in the command as you are entering at the command line. In fact, you should copy and paste from the debugger watch window into the command window.

    If cmd /c makes a difference then your startinfo object needs this setting:
    https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute(v=vs.110).aspx

    Also, you should post the exact, complete error message that you are getting.

    Persisting with code that you know doesn't work is pointless.

    (I presume that when you say 'my computer' you are not referring to a different machine.   If you are testing this at the command line on one machine and from code on another machine then that is the source of the problem).

    Tuesday, June 20, 2017 9:50 PM
  • Yes, my computer means only my machine.

    Source and used files are mine and why I'm not using exact string?

    A: I want to publish this very simple tool to retrocomputer users and they can have other config, even different Windows.

    For older Windows I created VB6 version.

    There's working also calling Java - this I understand not how, 'cause commandline produces failure.

    For newer OS I created VB.NET version and still in problems.

    I ignored not suggestion of Startinfo, look at code above - near all working with failure or same as now - like no argument...

    What I need exactly to do:

    Get info how can "java -cp" can work in VB6 (maybe missing this makes argument not processed)

    Get to process start with arguments

    Nothing more, nothing less...

    Thank you all for your patience.

    Miro

    Tuesday, June 20, 2017 10:20 PM
  • Code:
            Dim compiler As New Process()
            compiler.StartInfo.FileName = "java -cp"
            compiler.StartInfo.Arguments = QCesta & "model.vic20.StartVIC20"
            compiler.StartInfo.UseShellExecute = True
            compiler.StartInfo.RedirectStandardOutput = False
            compiler.Start()
    
    Error message:
    
    System.ComponentModel.Win32Exception occurred
      HResult=0x80004005
      Message=The system cannot find the file specified
      Source=<Cannot evaluate the exception source>
      StackTrace:
    <Cannot evaluate the exception stack trace>
    Here it is req'd to note - when I select Filename = QCesta then program starts, but again - no matter argument, always default.
    Tuesday, June 20, 2017 10:41 PM
  • Ok, I created subroutine:

       Public Sub ExcecuteCmd(ByVal parameters As String)
    
            'On Error GoTo Failure
    
            Process.Start(QCesta, parameters)
    
            End
    Failure:
            MsgBox("Process failed")
            End
    
        End Sub

    It works - but always arguments are no accepted...

    I mean now - you all helped me various ways to start it - problem is in Java calling command:

    Java -cp

    Is possible to get Java executable path in Windows?

    Miro

    Wednesday, June 21, 2017 1:29 AM
  • It works - but always arguments are no accepted...

    There is no possibility of providing assistance with the issue because you have not indicated what the values for  the two variables are.

    problem is in Java calling command:

    Java -cp

    If that is so, then the error has changed. You need to go back and confirm that the filename and argument work correctly when typed at a command prompt.  If the java executable can be found when entered on a command line, it can be found using a Startinfo object in Process.Start.

    Is possible to get Java executable path in Windows?

    Probably, but you will need to ask that in a java forum.   You also need to check that java is installed before looking for the installation path.

    If the problem is that you can't pass the command line argument to the java app then that implies that the path is being found automatically.


    • Edited by Acamar Wednesday, June 21, 2017 3:52 AM sp
    Wednesday, June 21, 2017 3:48 AM
  • So, I was desperate and downloaded and installed new Java... and success - it works.

    I used simple Shell command.

    Please forgive me that I wasted your time.

    Miro

    • Marked as answer by mksft Wednesday, June 21, 2017 11:39 AM
    Wednesday, June 21, 2017 11:38 AM