Author Topic: Console apps and folders with spaces.  (Read 2730 times)

AssemblyChallenge

  • Member
  • **
  • Posts: 110
Console apps and folders with spaces.
« on: November 10, 2017, 05:28:41 PM »
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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #1 on: November 13, 2017, 10:03:39 PM »
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

  • Member
  • **
  • Posts: 110
Re: Console apps and folders with spaces.
« Reply #2 on: November 14, 2017, 03:44:40 AM »
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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #3 on: November 14, 2017, 04:26:33 AM »
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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #4 on: November 16, 2017, 04:31:08 AM »
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

  • Member
  • *****
  • Posts: 8895
  • Assembler is fun ;-)
    • MasmBasic
Re: Console apps and folders with spaces.
« Reply #5 on: November 16, 2017, 04:41:16 AM »
executable 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

  • Member
  • **
  • Posts: 110
Re: Console apps and folders with spaces.
« Reply #6 on: November 16, 2017, 02:27:32 PM »
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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #7 on: November 17, 2017, 01:43:28 AM »
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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #8 on: November 17, 2017, 01:47:19 AM »
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

  • Member
  • **
  • Posts: 110
Re: Console apps and folders with spaces.
« Reply #9 on: January 10, 2018, 06:20:37 AM »
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:

Code: [Select]
.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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #10 on: January 10, 2018, 10:54:07 PM »
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

  • Member
  • **
  • Posts: 110
Re: Console apps and folders with spaces.
« Reply #11 on: January 11, 2018, 07:03:33 AM »
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:

Code: [Select]
.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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #12 on: January 11, 2018, 09:01:53 AM »
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

  • Member
  • **
  • Posts: 110
Re: Console apps and folders with spaces.
« Reply #13 on: January 12, 2018, 12:55:10 AM »
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

  • Moderator
  • Member
  • *****
  • Posts: 285
    • Easy Code
Re: Console apps and folders with spaces.
« Reply #14 on: January 12, 2018, 06:07:40 AM »
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