cwd property for spawned child processes #45963
Replies: 8 comments
-
If you use Adding a |
Beta Was this translation helpful? Give feedback.
-
@cjihrig What message should I pass to the forked process in order to discover the cwd? |
Beta Was this translation helpful? Give feedback.
-
That would be up to you. You'll fork a Node process with |
Beta Was this translation helpful? Give feedback.
-
What if this feature request were limited to child processes with a shell option set to true? A shell will know what its current directory is. That way the same code that is used for the |
Beta Was this translation helpful? Give feedback.
-
It won't work with the |
Beta Was this translation helpful? Give feedback.
-
No, I have not had any luck. I am writing a command terminal interface in a browser OS I am writing. I can already keep track of cwd for a user performing file system traversal, because everything executes through the current parent process where I am aware of state of all artifacts. Child processes are tricky because I have no idea what a user executed script might do, so when I report output to the user I have to find some way of determining what a given shell's current directory is only after the child process writes to stdout but before the next round of stdout |
Beta Was this translation helpful? Give feedback.
-
I'll convert this to a discussion because, like Colin said, this can't be implemented in a cross-platform manner. Even if it could, it'd be pretty useless because of how race-y it'd be: by the time you know the child's working directory, it may have chdir'd again. |
Beta Was this translation helpful? Give feedback.
-
What is the problem this feature will solve?
The current working directory of a Node parent process is conveniently available as
process.cwd()
, but there is no such solution for a child process. If a command changes the directory of a child process there is no messaging from child process to parent indicating that change and there is no Node solution to ask what the child's current directory is.What is the feature you are proposing to solve the problem?
I request a
cwd()
method for spawned child processes. Example:What alternatives have you considered?
I have looked into writing my own solution by writing to the child process's stdin, but this is wildly complicated cross OS and it is asynchronous which results in timing variations apart from stdin/stdout messaging.
Beta Was this translation helpful? Give feedback.
All reactions