zoukankan      html  css  js  c++  java
  • bash 转换为C代码

    bash 转换为C代码,并编译为可执行文件

    [root@localhost ~]# wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgz
    [root@localhost ~]# tar xvfz shc-3.8.9.tgz
    [root@localhost ~]# cd shc-3.8.9
    
    [root@localhost shc-3.8.9]# gcc -c shc.c
    [root@localhost shc-3.8.9]# gcc -o shc shc.o
    [root@localhost shc-3.8.9]# cp -a shc /bin/
    
    [root@localhost ~]# shc -r -T -f wang.sh
    [root@localhost ~]# gcc -c wang.sh.x.c
    [root@localhost ~]# gcc -o wang wang.sh.x.o
    

    将python代码转换为C代码

    [root@localhost ~]# yum install -y epel-release
    [root@localhost ~]# yum install -y python-pip
    [root@localhost ~]# yum install -y python-dev*
    [root@localhost ~]# pip install cython
    
    [root@localhost ~]# vim lyshark.py
    
    [root@localhost ~]# cython lyshark.py --embed
    [root@localhost ~]# gcc `python-config --cflags` `python-config --ldflags` lyshark.c -o lyshark
    

    C语言调用shell命令,并返回结果

    #include <stdio.h>
    
    int main()
    {
            FILE * fp;
            char buffer[1024];
            fp=popen("free -h |grep 'Mem:' |awk '{print $2}'","r");
            fgets(buffer,sizeof(buffer),fp);
            printf("%s",buffer);
            pclose(fp);
    
            return 0;
    }
    

    #include "stdafx.h"
    #include <Windows.h>
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	char   psBuffer[128];
    
    	FILE   *pPipe;
    
    	char * wang;
    
    
    	pPipe = _popen("dir", "rt");
    	fgets(psBuffer, 128, pPipe);
    
    	printf("%s",psBuffer);
    
    	feof(pPipe);
    
    	system("pause");
    
    	return 0;
    }
    
  • 相关阅读:
    异常
    动态链接库与静态链接库的区别
    OpenBLAS 安装与使用
    Eigen 优化技巧
    C++读取保存为二进制的 numpy 数组
    Sublime Text Windows版使用Conda环境
    Repeater 时间格式化
    C#与js的各种交互
    js 实现精确加减乘除
    常用正则表达式
  • 原文地址:https://www.cnblogs.com/LyShark/p/10889555.html
Copyright © 2011-2022 走看看