[Windows 10] Help manually setting command line variables


#1

Hi everyone!

I have a custom (portable) installation of Atom because I prefer so. Problem is, it seems my manual set up of system variable on Windows recognizes apm but not atom. Let’s see it in more detail.

Atom is installed (or better said, extracted) in: C:\Program Files (Portable)\Atom. “Program Files (Portable)” is a folder I created amongst “Program Files” and "Program Files (x86), specifically to gather portable software. But no problem here.

In system variables, ATOM_HOME is set to G:\DATA\Atom.atom. No problem here neither. Atom sees the directory and uses it normally.

In the “Path” variable, I’ve set C:\Program Files (Portable)\Atom\resources\cli, because both apm and atom command line resides there.

Now, if I open a command prompt (it points to C:\Windows\System32 by default) and type apm --help, I can see the command is executed and I have a list of possible parameters for apm. But, if I type atom --help, I get:

\Atom\resources\cli\…\atom.exe" -ArgumentList "–pid not expected.

Whatever I type, I get the same result. What could it be? Any help would be much appreciated. Not that I use the command line so often, but I would like to narrow down this issue.

Thank you in advance,
Alpha.


#3

Hello.

I have tried something similar on my Windows7 machine on Atom V1.20 Beta7.

What you describe should work.
Do make sure that you have the following when it is the first entry:
"C:\Program Files (Portable)\Atom\resources\cli";
Note the " and the ;characters.

Next… when you changed the environment variable (such as PATH), make sure you close the command prompt and re-open it again before testing. I have seen a mention somewhere that it might even be needed to log-out and log-in again… but of this I am not sure of.

Additional note ->

Why is there a mention of exe in the quoted message?
The command in the "C:\Program Files (Portable)\Atom\resources\cli" directory is atom.cmd.

Your thoughts?


#4

I’ve never seen that error before. Could you post a screenshot of it?


#5

Hello danPatrick and and DamnedScholar!

I will provide a screenshot of course, but let me answer to the two dan’s points first.

First one: no problem with " and ; - proof is that apm is recognized and executed.
Second one: as to why atom.exe, in the cli folder there is atom.cmd indeed, but if you inspect the content of the file, it is as follows:

@echo off

SET EXPECT_OUTPUT=
SET WAIT=
SET PSARGS=%*

FOR %%a IN (%*) DO (
  IF /I "%%a"=="-f"               SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--foreground"     SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="-h"               SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--help"           SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="-t"               SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--test"           SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--benchmark"      SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--benchmark-test" SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="-v"               SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--version"        SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="-w"           (
    SET EXPECT_OUTPUT=YES
    SET WAIT=YES
  )
  IF /I "%%a"=="--wait"       (
    SET EXPECT_OUTPUT=YES
    SET WAIT=YES
  )
)

IF "%EXPECT_OUTPUT%"=="YES" (
  SET ELECTRON_ENABLE_LOGGING=YES
  IF "%WAIT%"=="YES" (
    powershell -noexit "Start-Process -FilePath \"%~dp0\..\..\atom.exe\" -ArgumentList \"--pid=$pid $env:PSARGS\" ; wait-event"
    exit 0
  ) ELSE (
    "%~dp0\..\..\atom.exe" %*
  )
) ELSE (
  "%~dp0\..\app\apm\bin\node.exe" "%~dp0\atom.js" %*
)

As you can see, there is a redirection to atom.exe inside the file, this is in my opinion the reason why the output shows atom.exe.

And here is the screenshot. Not that “non atteso” means “not expected” in my language (Italian).

080

Thank you both guys for your interest in my issue. What could it be??? :thinking:


#6

Sorry, I mean: Note that “non atteso” means “not expected” in my language.
How can I edit my posts? I cannot find an option for it!


#7

Hi.

I was focussing on the wrong thing. :blush:
The problem is with the execution of the command line inside atom.cmd.

Mine has the last if-structure as:

IF "%EXPECT_OUTPUT%"=="YES" (
  IF "%WAIT%"=="YES" (
    powershell -noexit "Start-Process -FilePath \"%~dp0\..\..\atom.exe\" -ArgumentList \"--pid=$pid $env:PSARGS\" ; wait-event"
    exit 0
  ) ELSE (
    "%~dp0\..\..\atom.exe" %*
  )
) ELSE (
  "%~dp0\..\app\apm\bin\node.exe" "%~dp0\atom.js" %*
)

Not sure why, but the problem is with:

powershell -noexit "Start-Process -FilePath \"%~dp0\..\..\atom.exe\" -ArgumentList \"--pid=$pid $env:PSARGS\" 

  • Can you call up powershell from the command prompt?
    There were some guys that suggested to restricted powershell functions a while back… for security issues.

  • What happens when using powershell instead of cmd?

  • What happens if you run cmd on admin level?


#8

Strange, strange, strange! :rage:
To answer your questions:

  • Yes, I can call up PowerShell from the command prompt
  • If I use powershell, both from the command prompt and from its native window, same error
  • Same error with running cmd and powershell on admin level.

Any thoughts at this point???


#9

A strange one indeed. All I can come up with for the moment is the question
if --pid is recognised on your non-english PC.
I am not sure if Get-Process -Id $pid is the same as --pid=$pid
As reference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process?view=powershell-5.1

The dirty way to get things up and running for the moment is to clear out the effected line. Replace powershell with rem powershell. Where rem is short for remark which means “comment this line out”. Effectively what it will do is that the “wait” attribute will cause the command to not run properly.


I have no other leads for the moment.
Could you please execute the following in your command prompt (cmd):

powershell Get-Host

Which version of powershell does it report back?


#10

Here it is:

Which will be the consequence of commenting that line out? What will it affect?


#11

As stated earlier:

In other words - when using -w as attribute, no command will execute and the command prompt will close. If the -w is not used, the process will run normally.

…my version of Powershell in Windows7 is version 2.


#12

Thank you danPadric! After commenting that line out, I tried atom --help from the command line and got the list of parameters. As you said, it works. Really, your help has been very useful. I thank you so much. :grinning::sunglasses:

And for what regards the “origin” of the error… future will tell. I will stay with the dirty comment-out at the moment.


#13

I have some good news - I might have a solution for you.
Replace the last code segment as follows:

IF "%EXPECT_OUTPUT%"=="YES" (
  IF "%WAIT%"=="YES" (
    powershell -noexit "$process = Start-Process -FilePath \"%~dp0\..\..\atom.exe\" -ArgumentList \"$env:PSARGS\" -PassThru ; $process.WaitForExit() ; exit"
  exit 0
  ) ELSE (
    "%~dp0\..\..\atom.exe" %*
  )
) ELSE (
  "%~dp0\..\app\apm\bin\node.exe" "%~dp0\atom.js" %*
)

This change will make it possible for -w to work AFAIK.
Please confirm that this works in your version of Powershell.

Cheers.


#14

Hi danPatric, sorry to say that it didn’t work.


#15

Hello.

Very sorry… I was not clear with the instructions of my request. To try and avoid further issues, please find the complete code:

@echo off

SET EXPECT_OUTPUT=
SET WAIT=
SET PSARGS=%*
SET ELECTRON_ENABLE_LOGGING=NO

FOR %%a IN (%*) DO (
  IF /I "%%a"=="-f"                         SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--foreground"               SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="-h"                         SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--help"                     SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="-t"                         SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--test"                     SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--benchmark"                SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--benchmark-test"           SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="-v"                         SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--version"                  SET EXPECT_OUTPUT=YES
  IF /I "%%a"=="--enable-electron-logging"  SET ELECTRON_ENABLE_LOGGING=YES
  IF /I "%%a"=="-w"           (
    SET EXPECT_OUTPUT=YES
    SET WAIT=YES
  )
  IF /I "%%a"=="--wait"       (
    SET EXPECT_OUTPUT=YES
    SET WAIT=YES
  )
)

IF "%EXPECT_OUTPUT%"=="YES" (
  IF "%WAIT%"=="YES" (
    powershell -noexit "$process = Start-Process -FilePath \"%~dp0\..\..\atom.exe\" -ArgumentList \"$env:PSARGS\"-PassThru ; $process.WaitForExit() ; exit"    
  ) ELSE (
    "%~dp0\..\..\atom.exe" %*
  )
) ELSE (
  "%~dp0\..\app\apm\bin\node.exe" "%~dp0\atom.js" %*
)

The above is the whole atom.cmd.



Discussion

Note that I have included the line:

SET ELECTRON_ENABLE_LOGGING=NO

In my original atom.cmd this was not even assigned. In your version the default is set to YES as soon as you use -w. There is an attribute that can give you that option if and when you want it:

 --enable-electron-logging  Enable low-level logging messages from Electron.  [boolean]

Example:
Executing the command ->

atom -w --enable-electron-logging "C:\Work Files\myFile.js"

Result will be:

  1. Activate logging of opening Atom, because of --enable-electron-logging

  2. Open Atom

  3. The file myFile.js will be open from path C:\Work Files\.
    Notice the ".
    If the file / directory does not exist, a “pretend” file will open.
    The “pretend” file will become a new “actual” file as soon as you press save in Atom.

    4. The command prompt will stay open for as long as Atom is open.
    The command prompt will auto close as soon as Atom is closed.
    Remark: changed code to suit design intent

  1. The command prompt will pause in powershell ‘mode’ until atom is closed.
    The command prompt will remain open.

If this resolves you problem, please consider marking the title of this topic with [SOLVED].

Thank you and best regards.
- Dan Padric


Additional notes: (notes for myself)
  • Assumption: AlphaUMi’s version of powershell seems to
    use see --pid a system attribute and fails to use it.

  • Assume: --pid is an attribute of the atom command.

    • --pid=$pid is the handling over of the process identity to the atom command?

    • How to hand over pid attribute without having powershell complain about it.

    • Why is this attribute is not mentioned in atom --help.

    • For what is the process identity of the atom.exe call needed by the call?

    • Will not having the pid attribute called for Atom cause a problem?

  • What process requires the pid? - perhaps used for logging actions?

    • How does the logging action work? … how is the process identity used?

    • Does it need a process identity number or is it a good to have?

  • Why is there a ELECTRON_ENABLE_LOGGING variable in atom.cmd ?


#16

Hi!

Even after copying the whole code, I get the same error, as in the last screenshot:
\Atom\resources\cli\…\atom.exe" -ArgumentList “$env:PSARGS”-PassThru ; $process.WaitForExit() ; exit" not expected. :pensive:

By the way, I’m using the latest stable release at the moment (1.19.7), but with previous versions I got the same behavior.


#17

That is unfortunate. My assumption must have been in error - there is more issues with that line of code.

My first thought is to have the trouble line change to:

powershell -noexit "$process = Start-Process -FilePath \"%~dp0\..\..\atom.exe\" -ArgumentList -PassThru ; $process.WaitForExit() ; exit" 

Above idea removes all mention of additional arguments.
This is however only speculation - I have no clue why you have this naughty behaviour.


BUT
I am not going to have my academical curiosity chew on your time more.
Best you keep the code change that comments out the line with rem.
Thank you for testing my suggestions… you have been a good sport. :+1:

One last note… just keep in mind that if you update your installation, you will have to replace the atom.cmd file each time you make such an update.

Go well.
- Dan Padric


#18

Hi Dan,

unfortunately, even your last change in that line doesn’t work. :confounded:
Enough, I can live with the rem comment-out line at the moment.

One last thing.
Are you one of the devs? If not, shouldn’t they be warned about this? Since I used a “stock”, unmodified version of the file, probably I am not the only one with this issue… probably the fact is that a lot of users do not care using the command line and are not aware of the problem. Where can I report issues so that this one can be putted to the dev’s attention?
I assume that it’s something related to PowerShell v5 (Windows 10), since Windows 7 (which you are using) is not affected. Do you agree?


#19

Hello.

I am not an Atom developer… :confused:
When it comes to ‘this’ world I am an amateur - I program (mainly) Siemens PLCs, not PCs.
I am very sorry for mistakenly creating a false impression.

Is the version of your Powershell the only issue? …@DamnedScholar would have mentioned something earlier if it was. Your PC being set for non-english or some security/anti-virus configuration, could also be considered.

Maybe the proper people are not looking at this topic. Please consider making a bug report - if one is not already there. Probably best place would be here: https://github.com/atom/atom/issues.

Thank you for borrowing me some of your time.
I hope you well.
- Dan Padric


#20

Don’t count on it. I don’t know anything about Powershell commands. I’ve used it a couple of times to run Powershell-specific scripts, but I barely know anything about its actual features and I’ve already devoted part of my brain to knowledge about zsh for when I’m on Linux.


#21

@DamnedScholar https://discuss.atom.io/u/damnedscholar, thank you for
your reply.

Please could you run atom from command prompt in Win10?
No edits to atom.cmd… just run it -
atom -w myfile.txt

You can replace the ‘myfile.txt’ with anything… even leave it out.

- Dan Padric