News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Console apps and folders with spaces.

Started by AssemblyChallenge, November 10, 2017, 05:28:41 PM

Previous topic - Next topic

AssemblyChallenge

Hi, good friend Ramon.

Several days ago I was sorting out some stuff in my computer and simply decided to run one of my tools. To my surprise, it crashed, as you can see in the attached images. After checking back and forth for incompatibilities -none found- I noted that crashing only happens if I put the exe file in a folder with spaces on its name, say:

c:\myapps\miprog.exe  --> all good
c:\my apps\miprog.exe --> crash

The program in question was finished months ago with one of the 2.01 versions of EC, also, it is a command line program (Visual one's are Ok).
Then, I took another program, finished two years ago and also crashed when copied on any folder with spaces. No big deal, I told myself, so in order to replicate the problem I created a new empty command line project ("Hello world") and after compiling... it doesn't crash  :dazzled:

Any light on this? Reading the history of fixes there is none I can find regarding this issue.

Thank you.

rsala

Hi friend,

I am at work now, but I will have a look when I can. However, I am afraid that is a Windows restriction. A whole path or a file name with spaces must be passed between doble quotes "c:\my apps\miprog.exe" and I do not remember if EC takes care of that (but I do not think so).

Regards!
EC coder

AssemblyChallenge

Interesting.

My poor programs don't even have the chance to complain, they crash right away :lol:

Yet, it is so simple as creating a new folder with spaces, put a copy of the app and double clicking in Explorer.

Really puzzled about this one. Let me know if I can help you.  :t

rsala

Hi again,

I created the "c:\my apps" folder (with a space), then created a default console program and it compiles and works fine, so I cannot see what you report. Could you send the failing project please?

Thanks in advance!
EC coder

rsala

There is no problem with EC v2 and folders with spaces. The only problem is that executable file (console or not console) can not have any space in its name, but that is a Windows restriction and there is nothing EC v2 can do about it.

Please make sure you have the latest version of EC v2.

Regards!
EC coder

jj2007

Quote from: rsala on November 16, 2017, 04:31:08 AMexecutable file (console or not console) can not have any space in its name, but that is a Windows restriction

Hi Ramon,

What exactly do you mean with that? See attachment with New Win32.exe, works fine on Win7-64...

AssemblyChallenge

Right. There are no problems in Windows with LFN (oniy deep structures) nor issues with spaces in names/folders, except when typing commands in CMD or doing scripting, where is always advisable to enclose those between double quotes.

Anyway, I had the chance to dig some more and here are my findings. I'm using one of my projects, the one I sent to Ramon by mail.

- Event Viewer is fun filled with 0x8000002 errors, they all come from the same address.
- MSDN and others say it's a "Data Misaligned", WinDbg agreed when debugged the app's crash dump.
- The error is not in my code portion but some other place (GetCommandLineA).

Please take a look at the attached info. WinDbg gave me the best insight, and thanks to that I was able to follow the code and spot the place where, supposedly, lies the problem. I welcome your views.  :biggrin:


rsala

Hi jj2007,

Glad to hear from you.

Of course it works fine if you run it from the Explorer as it takes care of the space in the file name, but try to run it from the console (a cmd box) and you will see that it cannot be launched if you do not enclose its name between double quotes.

So, I really do not know what we are exactly talking about, I mean, I do not know what EC v2 is suposed to do.

Regards.

EC coder

rsala

Hi AssemblyChallenge,

I am sorry if I am misunderstanding something, but as I was saying in my previous post I still do not know where the problem is. What is EC v2 doing wrong?

Regards.
EC coder

AssemblyChallenge

Sorry about the delay; busy & end of year vacations :biggrin:

A few more bits in order to clarify the issue: I didn't use GetCommandLineA in those projects, at least, not directly. The lines of interest in my code would be:


.Data

LineArguments DB 128 Dup(0)
Parameter1 DB "/?", 0
Parameter2 DB "-?", 0

.Start
  Invoke ArgClC, 1, Addr LineArguments
Invoke szCmpi, Offset LineArguments, Offset Parameter1, 2
Cmp Eax, 0
Je ShowInfo
Invoke szCmpi, Offset LineArguments, Offset Parameter2, 2
Cmp Eax, 0
Jne NoInfo
.
.
.
ShowInfo:
code
etc

NoInfo:
more
code


Most of my CMD tools start in a similar fashion as I use this to show info/help when invoked. From all the times I debugged with Olly there were no errors.  Maybe the good old fellas can spot some mistake here?

rsala

Hi,

To clarify this issue, please take your time to do an elementary ad-hoc (complete and failing) example so that I can see where the problem is.

Thanks in advance!
EC coder

AssemblyChallenge

I just finished testing with a small Project (following the above guidelines) and got the same, exact problem. For EasyCode, just create a Classic one, paste the code, save and build:


.Const

.Data?

.Data

hInst HINSTANCE NULL

ShowSomeInfo DB "Hi, you got info.", 13, 10, 0
DontShowInfo DB "There, no info for you.", 13, 10, 0

LineArguments DB 128 Dup(0)
Parameter1 DB "/?", 0
Parameter2 DB "-?", 0

.Code

start:
Invoke GetModuleHandle, NULL
Mov hInst, Eax

Invoke ArgClC, 1, Addr LineArguments
Invoke szCmpi, Offset LineArguments, Offset Parameter1, 2
Cmp Eax, 0
Je ShowInfo
Invoke szCmpi, Offset LineArguments, Offset Parameter2, 2
Cmp Eax, 0
Jne NoInfo

ShowInfo:
Invoke StdOut, Addr ShowSomeInfo
Jmp Bye

NoInfo:
Invoke StdOut, Addr DontShowInfo

Bye:
Invoke ExitProcess, 0
End start


In order to trigger the error just rename the resulting exe (ie: mytest.exe --> mytes t.exe). If you copy the normal exe into a folder with spaces like explained in the first entry, it works too. Right now I'm more inclined to believe this was my fault (but can't find where :dazzled:) or something funny is going on inside GetCommandLineA.

Ideas please?

rsala

Well, I created a 32-bit console project and pasted your text. It builds fine with no errors, so I attach the project for you.

As you can see in the Console.ecp file, I have all tools in drive G:
EC coder

AssemblyChallenge

I simply took your resulting \release\console.exe and rename it into consol e.exe and got the crash right away. Still wondering if there is something wrong with my code.

Edit: I took the same code, comented the "Invoke ArgClC, 1, Addr LineArguments" line and there is no error when using spaces in name/folder. I give up, where is the bug?

rsala

I do not know how Windows manages an executable file name with a space, but it seems to do that ONLY from the explorer, just when you double click on the file name. However, you cannot run it, for example, from a DOS box (cmd.exe). So I am sorry but I cannot do anything about that. Anyway, is a space really needed in an executable file name?
EC coder