Why a program doesn't work when run from a batch file, but works when clicked

devblogs.microsoft.com

73 points by ibobev 4 days ago


netsharc - 2 hours ago

With drive letters, a neat functionality in DOS/Windows command prompts (don't ask me about Powershell) is that each letter can have its own "current directory".

So if you have ffmpeg.exe in C:\Program Files\FFMpeg\bin, and you have some source files in D:\SourceVideos, and you want to process them in ffmpeg and output them to E:\Output you can do:

C: (to navigate to the C: drive)

cd "C:\Program Files\FFMpeg\bin"

E: (to navigate to the E:\ drive)

cd D:\SourceVideos (you remain in E:\, but the "current directory" for D: has been changed).

cd Output (to enter E:\Output)

You can now do C:ffmpeg.exe -i D:scene1.mp4 output-scene1.mp4

and Windows accesses the files in the "current" directory on each drive letter.

xg15 - 5 hours ago

> Explorer sets the current directory of the program to the directory containing the thing that you double-clicked

I found the linked article to informative and confirming my suspicion: "The thing that you clicked" doesn't have to be the executable - it could also be a document with the executable registered as launch handler, in which case the current directory will be the directory of the document.

Would be interesting to know how links and items in shell namespaces are handled.

tveita - 5 hours ago

How much are these customers paying for support to have Raymond Chen on first level support to debug their batch files?

PaulHoule - 2 hours ago

Well, there is no concept of "the current directory" in the UI of explorer.exe the way there is in CMD.EXE or Bash. You can have multiple directories open and none of them are privileged over the others.

I think of cultures of command line programs: the node ecosystem very much has the idea that a program "lives" in a a certain directory and you're always going to work with that program in that directory. This is convenient in a lot of ways but... say you are writing a data analysis program and you want to put it on your $PATH and then cd to the place where your data lives and do your work there?

lordnacho - an hour ago

A related issue is when you set up automation, and it turns out the automation script runs as a different user with different authorizations from the user who tested the script. It's just one of those little annoyances that appears when you try to go from "works on my machine" to "works".

niekverw - 3 hours ago

Appreciating that this is not AI generated

kaziabirwindev - 2 hours ago

[flagged]

arthurfirst - 3 hours ago

Is this an article from 1997?