# Enable "run\_file" for Sonic-Pi 2.10

**URL:** <https://in-thread.sonic-pi.net/t/enable-run-file-for-sonic-pi-2-10/2187>\
**Category:** Support, Help & Resources\
**Created:** [March 30, 2019, 11:00pm UTC](https://in-thread.sonic-pi.net/t/enable-run-file-for-sonic-pi-2-10/2187 "2019-03-30T23:00:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![minced\_mind](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@minced\_mind](https://in-thread.sonic-pi.net/u/minced_mind)\
**Post date:** [March 30, 2019, 11:00pm UTC](https://in-thread.sonic-pi.net/t/enable-run-file-for-sonic-pi-2-10/2187/1 "2019-03-30T23:00:36Z")

</div>

Hello Sonic-Pi community 🙂

Today, I hit the character limit for a buffer on Sonic-Pi and it is a real showstopper for me as I need way more complex code for my instrumentation etc.  
So I looked up the “run\_file” command as has been said from Robin Newman and others here in the forum.  
The problem is, it is only available for Sonic-Pi 2.11 and upwards. As I’m using Debian, Sonic-Pi is still on version 2.10 and building newer versions just for this small extension is a nuisance.  
So, I looked up this really small function in Sonic-Pi 2.11 and backported it to Sonic-Pi 2.10. Hope, I did nothing wrong here, at least it worked well for me 🙂  
Maybe others will need this, too, and don’t want the hassle of building a newer version just because of more complex songs etc.

So here is the patch for Debian 9 and maybe other Sonic-Pi distributions:  
— /usr/lib/sonic-pi/server/sonicpi/lib/sonicpi/lang/core.rb.orig 2016-04-15 15:17:08.000000000 +0200  
+++ /usr/lib/sonic-pi/server/sonicpi/lib/sonicpi/lang/core.rb 2019-03-30 23:44:08.425964723 +0100  
@@ -3115,6 +3115,24 @@  
examples: ["  
load\_example :rerezzed # will replace content of current buffer with the rerezzed example"]

- 
- 

```
 def run_file(path)

```

- 

```
   path = File.expand_path(path.to_s)

```

- 

```
   raise "Error - unable to run file - no file found with path: #{path}" unless File.exist?(path)

```

- 

```
   __spider_eval(File.read(path))

```

- 

```
 end

```

- 

```
 doc name: :run_file,

```

- 

```
     introduced: Version.new(2,11,0),

```

- 

```
     summary: "Evaluate the contents of the file as a new Run",

```

- 

```
     args: [[:filename, :path]],

```

- 

```
     returns: nil,

```

- 

```
     opts: nil,

```

- 

```
     accepts_block: false,

```

- 

```
     doc: "Reads the full contents of the file with `path` and executes it in a new Run. This works as if the code in the file was in a buffer and Run button was pressed.",

```

- 

```
     examples: ["

```

+run\_file “~/path/to/sonic-pi-code.rb” #=\> will run the contents of this file"]  
+  
+  
def \_\_on\_thread\_death(&block)  
gc\_jobs = Thread.current.thread\_variable\_get(:sonic\_pi\_\_not\_inherited\_\_spider\_in\_thread\_gc\_jobs) || []  
gc\_jobs \<\< block

---

<div class="post-metadata">

**Author:** ![minced\_mind](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@minced\_mind](https://in-thread.sonic-pi.net/u/minced_mind)\
**Post date:** [March 30, 2019, 11:02pm UTC](https://in-thread.sonic-pi.net/t/enable-run-file-for-sonic-pi-2-10/2187/2 "2019-03-30T23:02:09Z")

</div>

Argh, forgot formatting, here in a better variant:

```ruby
--- /usr/lib/sonic-pi/server/sonicpi/lib/sonicpi/lang/core.rb.orig	2016-04-15 15:17:08.000000000 +0200
+++ /usr/lib/sonic-pi/server/sonicpi/lib/sonicpi/lang/core.rb	2019-03-30 23:44:08.425964723 +0100
@@ -3115,6 +3115,24 @@
           examples: ["
 load_example :rerezzed # will replace content of current buffer with the rerezzed example"]
 
+
+ def run_file(path)
+ path = File.expand_path(path.to_s)
+ raise "Error - unable to run file - no file found with path: #{path}" unless File.exist?(path)
+ __spider_eval(File.read(path))
+ end
+ doc name: :run_file,
+ introduced: Version.new(2,11,0),
+ summary: "Evaluate the contents of the file as a new Run",
+ args: [[:filename, :path]],
+ returns: nil,
+ opts: nil,
+ accepts_block: false,
+ doc: "Reads the full contents of the file with `path` and executes it in a new Run. This works as if the code in the file was in a buffer and Run button was pressed.",
+ examples: ["
+run_file \"~/path/to/sonic-pi-code.rb\" #=> will run the contents of this file"]
+
+
       def __on_thread_death(&block)
         gc_jobs = Thread.current.thread_variable_get(:sonic_pi __not_inherited__ spider_in_thread_gc_jobs) || []
         gc_jobs << block

```
