Any way to compile C remotely?

I found many ways to work remotely in Komodo, using scp publishing and macros to send commands, I think is possible to compile c using commands remotely, sadly I can not figure it how to do it yet.

Actually I am uploading my C files using komodo SCP server tool (a remote project file, not using publishing tool).

These are the commands I need to run on the remote server to compile and run the program (it’s a linux server):

gcc my_program.c -o my_program

There is any way to send these commands and get the answer on the Komodo Console?

Thank you in advance!

Hi, you could try creating a new toolbox command (Tools > Run Command… and then check “Add to Toolbox”) that executes your compile command remotely on a server. I’m not exactly sure what the syntax would be, but I’m pretty sure ssh allows this. Any output should be printed in Komodo’s output window.

Thank you mitchell, I can not figure it yet, to run a remote command I need to give komodo an user, password and address to connect, Where can I write these parameters?

I use a command to restart a remote web server; you can probably adapt it to do what you want:

You’ll probably want to use the “parse output with” and/or “open output pane” to see whatever it does.

(For reference, the ‘web bounce’ command I use is a shell script that does the magic work; you’d probably want a similar script on the remote end.)

Don’t forget to redirect stderr to stdout.

Understood, but I still missing something, how komodo will know the remote address to run this command?

Are you setting these data on the “web bounce” file?
Can I see this file?

Komodo does not resolve the remote IP, it just runs ssh which is doing the magic. You can define ~/.ssh/config file with something like that:

Host hostname
    HostName your_ip
    Port 22
    User root

And then access it by ssh hostname (in case you’re using a ssh key).
I’m not sure there’s a way to send a password using an argument for ssh command so the only way to do that is generate a ssh key and send it to the server so they key will be trusted.

You can do some search on Google about it or:

the script run on the remote (the bits in single-quotes after the host) is just a plain ol’ shell script. I don’t want to put the actual script here (I guess it’s technically company proprietary :slight_smile:) but you can imagine it saying something like:

#!/bin/sh action=$1 sudo /usr/bin/something $ACTION

I connect via SSH with a key so I don’t need to enter a password.

Hi @stramin,

There is a Userscript for this:

It piggybacks on the current files remote connection so you’ll have to have a file open from the remote server which I assume you do.

If that work flow doesn’t work for you we can figure out a way that you could pick a server configuration from you preferences and use that to maintain the connection to pass commands across.

  • Carey
1 Like

With this one you have to redirect stderr to stdout.

Hi @careyh ,

Sorry, I don’t know what to do with that link, it have a link to a script, I don’t know what to do with it, I don’t know enough about userscripts yet.

Should I copy/paste it in a new userscript in my toolbox?

Ok, I think I did it, how can I redirect stderr to stdout as defman said?

Ok, I did that too, I am receiving output on the notifications pane (ko.notification.add).

How can I get this output on the console pane instead of notification pane?


Try this:

Once you’ve run that Userscript you’ll have access to the print_to_output_tab function globally so you can call it like print_to_output_tab(stdout).

  • Carey
1 Like

Usefull! I didn’t know you can declare functions globally, I got some logs in console using this:

var w = document.getElementById('console-widget').contentWindow;
w.document.getElementById('output').innerHTML = ''; // clear console (thanks to nathanr)

if(stderr.value!="") console.error(stderr.value); // prints errors if any
else console.log(stdout.value); // else prints output

Thank you!

Anything declared without var is automatically made global. Note, this is terrible practice and you should never do it in your code and that Userscript should be re-written to NOT do it :slight_smile: but I have to get to work on 10.1 features otherwise I would fix it :stuck_out_tongue: .

  • Carey
1 Like

Unless that variable was previous declared locally of course. Javascript gotchas ftw!

Note that this is why it is usually better to be explicit with your global variables by declaring it on the window object, ie. window.var = 'foo' instead of var = foo.

1 Like