vscode-code-runner icon indicating copy to clipboard operation
vscode-code-runner copied to clipboard

Suggestion: about temporary file

Open Xeonacid opened this issue 7 years ago • 26 comments

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?

Xeonacid avatar Aug 04 '18 11:08 Xeonacid

Are you running it in terminal? If not in terminal, it should be removed.

formulahendry avatar Aug 04 '18 11:08 formulahendry

@formulahendry Yeah, I'm running it in terminal.

Xeonacid avatar Aug 04 '18 12:08 Xeonacid

OK, for now, you could customize the code-runner.executorMap by yourself.

formulahendry avatar Aug 04 '18 12:08 formulahendry

@formulahendry Could you give an example?

Xeonacid avatar Aug 04 '18 12:08 Xeonacid

Please refer to https://github.com/formulahendry/vscode-code-runner#configuration

formulahendry avatar Aug 04 '18 12:08 formulahendry

@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?

Xeonacid avatar Aug 04 '18 13:08 Xeonacid

You could just use $fullFileName or $fileName, e.g. `"python": "python $fullFileName && del $fullFileName". And, currently it is no support to set globally.

formulahendry avatar Aug 04 '18 13:08 formulahendry

@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

Xeonacid avatar Aug 04 '18 13:08 Xeonacid

Oh... You are right...

formulahendry avatar Aug 04 '18 14:08 formulahendry

Or just use something like "python": "python $fullFileName && del tempCodeRunnerFile.py"

formulahendry avatar Aug 04 '18 14:08 formulahendry

@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!

Xeonacid avatar Aug 04 '18 14:08 Xeonacid

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!

filipesilva avatar Feb 23 '19 14:02 filipesilva

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:

  • I am on Windows, using GitBash, and running on terminal.
  • the -f flag is needed to prevent rm: cannot remove 'path/here': No such file or directory when running the real file (without a selection).
  • using $dirWithoutTrailingSlash is needed because the path is surrounded by quotes and the final slash on windows will escape the quote.
  • double escaped slashes (\\\\) are needed otherwise it will end up as \tempCodeRunnerFile, and \t means escape t.
  • will not delete the file if code execution fails.

It works but there are a few things to keep in mind when doing it manually.

filipesilva avatar Feb 23 '19 15:02 filipesilva

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.

mil1i avatar Mar 22 '19 04:03 mil1i

also not getting removed for me with or without "Run in Terminal"

tgreen7 avatar Mar 31 '19 06:03 tgreen7

Why not just create those temp files in system temp dir?

cherry-geqi avatar Apr 11 '19 09:04 cherry-geqi

@cherry-geqi the file system environment often matters even for snippets. Mostly for imports, but sometimes for global definitions.

filipesilva avatar Apr 11 '19 10:04 filipesilva

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.

cherry-geqi avatar Apr 11 '19 10:04 cherry-geqi

That's a great idea!

filipesilva avatar Apr 11 '19 10:04 filipesilva

@cherry-geqi Sounds good, but it's not a robust way...

Xeonacid avatar Apr 11 '19 22:04 Xeonacid

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:

  • I am on Windows, using GitBash, and running on terminal.
  • the -f flag is needed to prevent rm: cannot remove 'path/here': No such file or directory when running the real file (without a selection).
  • using $dirWithoutTrailingSlash is needed because the path is surrounded by quotes and the final slash on windows will escape the quote.
  • double escaped slashes (\\\\) are needed otherwise it will end up as \tempCodeRunnerFile, and \t means escape t.
  • will not delete the file if code execution fails.

It works but there are a few things to keep in mind when doing it manually.

I know it's a bit late, but since this issue is still open ... this isn't working for me - also windows btw Remove-Item: Parameter cannot be processed because the parameter name 'f' is ambiguous. Possible matches include: -Filter -Force.

therefore tinkered a bit around and made this work: "javascript": "clear && node $fullFileName && rm $fullFileName" using clear because getting PS C:\Projects\vscodium\time table> node "c:\Projects\vscodium\time table\public\js\tempCodeRunnerFile.js" ; if ($?) { rm "c:\Projects\vscodium\time table\public\js\tempCodeRunnerFile.js" } before the output - haven't yet figured out how to remove this, but clear does the job - would be nice tho having an another solution - so I can scroll and check the previous outputs

DadoIrie avatar Oct 24 '22 17:10 DadoIrie

Amazing that not more people are complaining about this - I had no idea what was generating these files and finally Googled the filename. There should definitely be an option to delete the temporary file if running via a console - temporary files are just that so why keep them after executing?

AMMullan avatar Dec 08 '22 12:12 AMMullan

Following up on filipesilva's answer above, anyone facing this issue on linux and running on terminal may try this:

  "code-runner.executorMap": {
    "javascript": "node $fullFileName && rm -f $dirWithoutTrailingSlash\ttempCodeRunnerFile.js",
    "python": "python $fullFileName && rm -f $dirWithoutTrailingSlash\ttempCodeRunnerFile.py",
    "typescript": "ts-node $fullFileName && rm -f $dirWithoutTrailingSlash\ttempCodeRunnerFile.cljs",
    "clojure": "lumo $fullFileName && rm -f $dirWithoutTrailingSlash\ttempCodeRunnerFile.cljs",
  },

DigDogData avatar Jun 02 '23 18:06 DigDogData

sorry to necro, but i didn't like the above solutions, so i forked the project and changed a few lines to allow entire paths for the Temporary File Name setting, and also removed the quotes from all customized parameters

if anyone is interested: https://github.com/ericchase/fork--vscode-code-runner

ericchase avatar May 26 '24 13:05 ericchase