File will not open after passing command line argument

G

Guest

The only code that is helpful is this:
fp = New IO.StreamReader(filename, New
System.Text.UnicodeEncoding(True, False), False)
If I pass a command line argument to my program that is not from Visual
Studio.NET is debug mode, the above code won't work, even though filename is
not changed whether I pass a command line argument or not. By not work, I
mean it will set fp.EndOfStream to true and fp.Peek() returns -1. The command
line argument is a file name, but not "filename" and is irrelevant. The file
is not concurrently open by any other program. Can someone please help me or
tell me how to work around what is probably is bug in VB.NET?
 
B

Bill McCarthy

Hi Forrest,

Does the code work if you run it in Visual Studio by setting the command
line arguments to the same filename in the Debug tab tot the Project
properties ?
Can you show the code that populates the filename variable ?

EG:

Sub Main(args() as String)
filename = args(0)

?
 
G

Guest

The file name is a constant:
Public Const CONFIG_LIST_FILE As String = "config_files.txt"
.....
configurations = get_configurations(CONFIG_LIST_FILE)
Public Function get_configurations(ByRef filename As String) As ArrayList
....

The Command line argument from Debug mode set in Visual Studio.NET under the
debug tab:
"C:\Documents and Settings\s\My Documents\Visual Studio Projects\Alarm Clock
of Justice\bin\Configuration3.xml"

But again, when I drag a file over the .exe produced in the /bin directory
(the most recent build of my debug version), the problem above appears, but
not when I pass the command line argument (with or without quotes) in
VS.NET's debug tab.
 
G

Guest

Oh whoops: here is the code that gets the command line arguments:
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim i, cnt As Integer
'get cmd line params--for some reason they come with quotes (")
attached--guess this isn't Unix
Dim prog_args As String =
Microsoft.VisualBasic.Command().Replace("""", "")
 
G

Guest

Triple post. I feel terrible.
For full disclosure, here is all code executed in Mainform_load until the
get_configuration_list call

'failure to load config list?
Dim load_failure As Boolean = True
'let the DLL know the HWND
set_acoj_window(Me.Handle)
'set the parent of the reminder form to be me
rm.mparent = Me
'get configuration list
configurations = get_configurations(CONFIG_LIST_FILE)
 
B

Bill McCarthy

Hi Forrest,

Sorry I can reproduce from the information you've given. I'm lost as to how
a constant for the filename comes into play.

The only thing I can think of is if you have different debug and release
paths, perhaps that's giving you a different file.

Bill.
 
B

Bill McCarthy

As I said earlier, I'm lost on this code as it appears you are using a
constant, CONFIG_LIST_FILE, not the actual command line argument.

BTW: for the command line argument you can use
Environment.GetCommandLineArgs, . Index 0 is your exe, index 1 is the first
argument. ,eg.:
filename = Environment.GetCommandLineArgs(1)
That will avoid the need to remove any enclosing quotation marks.
 
G

Guest

Yeah, I know. It's the oddest thing. I don't know why it happens, either.
The file paths are the same and I will try that Environment method of getting
command line arguments you mentioned earlier.
 
G

Guest

I changed the file path to an absolute one with Application.GetStartupPath
and that worked! I don't know why, though, because a file without a specified
path is searched for in the current directory, right? As long as it
works...Thanks for your help, Bill.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top