Currently, after running selected code in Code Runner, it leaves a temporary file with the name set in code-runner.temporaryFileName in working dir. If we don't need that any more, we have to remove it manually.
What about adding a setting about whether the temporary file would be removed automatically after running?
Are you running it in terminal? If not in terminal, it should be removed.
@formulahendry Yeah, I'm running it in terminal.
OK, for now, you could customize the code-runner.executorMap by yourself.
@formulahendry Could you give an example?
@formulahendry I've read this, but sorry for that I have no idea about how to determine whether it's running a temporary file. 馃槩 Could it read the code-runner.temporaryFileName variable? I would really appreciate it if you could give a little example...
BTW, the code-runner.executorMap is separate settings for each language. Does it have any possible to set globally?
You could just use $fullFileName or $fileName, e.g. `"python": "python $fullFileName && del $fullFileName". And, currently it is no support to set globally.
@formulahendry Thanks a lot, but... this would make an unconditional removal, whether it's the temporary file created by running selected code or not. TAT
Oh... You are right...
Or just use something like "python": "python $fullFileName && del tempCodeRunnerFile.py"
@formulahendry Thanks! (To be honest, I've been using in this way before opening this issue :P
It would be grateful if you could implement a global setting as mentioned above, and/or make variables like the code-runner.temporaryFileName visiable in the code-runner.executorMap!
I was also trying to find a workaround/solution for this situation. I can do && rm tempCodeRunnerFile.js for now though, that's fine enough. But it would be a cool option. Thanks for your work!
For those interested, this is how my executorMap looks like for the languages I use:
"code-runner.executorMap": {
"javascript": "node $fullFileName && rm -f $dirWithoutTrailingSlash\\\\tempCodeRunnerFile.js",
"typescript": "ts-node $fullFileName && rm -f $dirWithoutTrailingSlash\\\\tempCodeRunnerFile.cljs",
"clojure": "lumo $fullFileName && rm -f $dirWithoutTrailingSlash\\\\tempCodeRunnerFile.cljs",
},
Notes:
-f flag is needed to prevent rm: cannot remove 'path/here': No such file or directory when running the real file (without a selection).$dirWithoutTrailingSlash is needed because the path is surrounded by quotes and the final slash on windows will escape the quote.\\\\) are needed otherwise it will end up as \tempCodeRunnerFile, and \t means escape t.It works but there are a few things to keep in mind when doing it manually.
It is not deleting the temp files for me whether it is run in Output or Terminal. They always persist. Doesn't matter which language either.
In order for them to delete, I must use the mappings like above with a 'rm tempCodeRunnerFile.
also not getting removed for me with or without "Run in Terminal"
Why not just create those temp files in system temp dir?
@cherry-geqi the file system environment often matters even for snippets. Mostly for imports, but sometimes for global definitions.
As far as I know, many executors accept scripts from stdin.
Instead
node /path/to/script.js
We can
node < /path/to/script.js
This will avoid the env issues.
That's a great idea!
@cherry-geqi Sounds good, but it's not a robust way...
Most helpful comment
It is not deleting the temp files for me whether it is run in Output or Terminal. They always persist. Doesn't matter which language either.
In order for them to delete, I must use the mappings like above with a 'rm tempCodeRunnerFile.' command at the end.