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;
}
原文地址:https://www.cnblogs.com/LyShark/p/10889555.html