2015-06-12 2 views
0

У меня есть brick.sprite. У меня есть исполняемый файл в Debain 8 "Kali Linux" с этим кодом:linux stdin, stdout pipe

#include <stdio.h> 
 
#include <stdint.h> 
 
#include <iostream> 
 

 
/** 
 
    * To use this file, pipe a sprite of the old format into stdin, and 
 
    * redirect stdout to a second file of your chosing. The sprite header 
 
    * will be converted. This tool has no error checking and assumes a valid 
 
    * sprite header. It is provided merely for convenience. 
 
    */ 
 

 
int main(int argc, char *argv[]) 
 
{ 
 
    uint8_t zero = 0; 
 
    uint8_t val; 
 
    int ret; 
 

 
    /* Read in old width */ 
 
    ret = fread(&val, sizeof(val), 1, stdin); 
 
    /* Write empty value and then new */ 
 
    fwrite(&zero, sizeof(zero), 1, stdout); 
 
    fwrite(&val, sizeof(val), 1, stdout); 
 
    
 
    /* Read in old height */ 
 
    ret = fread(&val, sizeof(val), 1, stdin); 
 
\t \t 
 

 
    /* Write empty value and then new */ 
 
    fwrite(&zero, sizeof(zero), 1, stdout); 
 
    fwrite(&val, sizeof(val), 1, stdout); 
 

 
    /* Straight copy of bitdepth and format */ 
 
    ret = fread(&val, sizeof(val), 1, stdin); 
 
    fwrite(&val, sizeof(val), 1, stdout); 
 

 
    ret = fread(&val, sizeof(val), 1, stdin); 
 
    fwrite(&val, sizeof(val), 1, stdout); 
 

 
    /* Assuming horizontal and vertical stride of 1 */ 
 
    val = 1; 
 
    fwrite(&val, sizeof(val), 1, stdout); 
 
    fwrite(&val, sizeof(val), 1, stdout); 
 
\t 
 
\t printf("%d\n",ret);//set to avoid weird error 
 

 
    /* Now just byte copy until end of stream */ 
 
    while(!feof(stdin)) 
 
    { 
 
     ret = fread(&val, sizeof(val), 1, stdin); 
 
     
 
     if(!feof(stdin)) 
 
     { 
 
      /* Only copy out if the last read didn't make an eof */ 
 
      fwrite(&val, sizeof(val), 1, stdout); 
 
     } 
 
    } 
 

 
    return 0; 
 
}

для преобразования brick.sprite в новый формат. Я попробовал его со многими кодами:

//convtool is the executable 
 
convtool grep <brick.sprite date > brick2.sprite 
 
convtool <brick.sprite> brick2.sprite //This looks like that it goes in the right way... 
 
convtool cat <brick.sprite> brick2.sprite 
 
convtool 2> brick2.sprite > brick.sprite

Я не знаком с Linux, но мне нужно знать.

Спасибо за советы!

+0

Какой тип файла 'brick.sprite'? –

+0

Большое вам спасибо! Это файл png, преобразованный в .sprite в двоичном формате. – Hexdec

ответ

0

Если вы намерены перенаправить содержимое вашего файла «brick.sprite» на stdin «convtool», вы используете оператор <.

convtool < brick.sprite 

Альтернатива была бы кошку (записать содержимое файла на стандартный вывод) содержание и трубы его в свой инструмент.

cat brick.sprite | convtool 

Это швы, что вы также хотите перенаправить вывод вашего инструмента на новый файл brick2.sprite. Перенаправление вывода в файл выполняется оператором >.

Чтобы завершить оба варианта сверху:

convtool <brick.sprite> brick2.sprite 
cat brick.sprite | convtool > brick2.sprite 

Первый вариант schould также работают на окнах и OSX оболочках не Linux специфичны.

Некоторые советы:

// This is complete nonsense. 
// you use the name of linux tools/commands as argument of convtools. 
convtool grep <brick.sprite date > brick2.sprite 

//This looks like that it goes in the right way... 
// this is one of the right ways ;-) 
convtool <brick.sprite> brick2.sprite 

// your convtool does not use arguments. 
// But i think this would work too. "cat" is nonsense. 
convtool cat <brick.sprite> brick2.sprite 

// after performing this command you have written the eeror output stderr 
// to your brick2.sprite file and you have overwritten your 
// brick.sprite file with the std out. (I hope you have a copy ;-) 
convtool 2> brick2.sprite > brick.sprite 
+0

Спасибо, я никогда не сталкивался с тем, что я получу такой ответ. Ты помог мне. – Hexdec

Смежные вопросы