码迷,mamicode.com
首页 > 其他好文 > 详细

sublime text 3 远程编译

时间:2015-08-10 17:40:41      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

最近研究算法,用C语言,但是机器上不想安装cygwin,也不想安装vc,vs等等,公司有闲置linux机器,所以就有了本文

最后成果:

技术分享

 

1.安装sublime text 3 

2.点击-->tool-->Build System-->New Build System 后编辑文本 保存为C:\Users\Administrator\AppData\Roaming\Sublime Text 3\Packages\User\python-c.sublime-build (本人windows机器路径)

表示python-c 构建系统 使用命令为 python e:/scriptworkspace/compile_c.py $file  可以个人根据自己配置做替换

{
    "cmd": ["python", "e:/scriptworkspace/compile_c.py","$file"],
    "selector": "source.python"
}

技术分享

3.编写compile_c.py 保存为e:/scriptworkspace/compile_c.py

注意事项:

  3.1 pip install paramiko (该命令为python ssh模块,安装失败需自己查明原因)

  3.2 远程的linux机器 需安装有g++ ,笔者使用的是centos 6.4 默认安装有,大多数linux 发行版都会有

import sys

#pip install paramiko
import paramiko

ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("192.168.0.32",22,"root", "123456")

t = paramiko.Transport(("192.168.0.32",22))
t.connect(username = "root", password = "123456")
sftp = paramiko.SFTPClient.from_transport(t)

remotepath=/root/temp.c
localpath=sys.argv[1]
sftp.put(localpath,remotepath)


stdin,stdout,stderr=ssh.exec_command("g++ -o temp temp.c")
lines= stderr.readlines()
if lines:
    for line in lines:
        print "[error]",line.encode("utf-8")

stdin,stdout,stderr=ssh.exec_command("/root/temp")
lines= stdout.readlines()
for line in lines:
    print line
ssh.exec_command("rm -f /root/temp.c /root/temp")

t.close()
ssh.close()

 

4.写个简单C语言程序,测试

#include "stdio.h"
int main(){
    printf("hello world\n");
    return 0;
}

 st(sublime text) 选中 tools-->Build System-->python-c 后 按键ctrl+b 即可以看到执行结果

sublime text 3 远程编译

标签:

原文地址:http://www.cnblogs.com/mmdsnb/p/4718528.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!