使用Perl Net :: SSH :: Perl检查远程目录是否存在
我想使用Net :: SSH :: Perl模块检查报表服务器上是否存在目录。
此命令有效:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct BitMap {
short Type;
long Size;
short Reserve1;
short Reserve2;
long OffBits;
long biSize;
long biWidth;
long biHeight;
short biPlanes;
short biBitCount;
long biCompression;
long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
long biClrUsed;
long biClrImportant; } Header;
unsigned char DummyValueRead ; unsigned char pixelValue =0 ;
int Horizontal= 0 ,Vertical = 0 ;
long myPalette[2]; long HeaderBytes;
unsigned char bPadding ; long wBytesPerRow ; unsigned char
bAdditionalBitsPerRow ; FILE *BMPFile; void SendPixelValues();
unsigned char input ;
int main( void ) {
BMPFile = fopen ("mul.bmp", "r");
if (BMPFile == NULL)
{
printf("Image Not Found !!!!!!");
return -1;
}
fread(&Header.Type, sizeof(Header.Type), 1, BMPFile);
fread(&Header.Size, sizeof(Header.Size), 1, BMPFile);
fread(&Header.Reserve1, sizeof(Header.Reserve1) , 1, BMPFile);
fread(&Header.Reserve2, sizeof(Header.Reserve2) , 1, BMPFile);
fread(&Header.OffBits, sizeof(Header.OffBits), 1, BMPFile);
fread(&Header.biSize, sizeof(Header.biSize), 1, BMPFile);
fread(&Header.biWidth, sizeof(Header.biWidth), 1, BMPFile);
fread(&Header.biHeight, sizeof(Header.biHeight) , 1, BMPFile);
fread(&Header.biPlanes, sizeof(Header.biClrUsed), 1, BMPFile);
fread(&Header.biBitCount, sizeof(Header.biBitCount), 1, BMPFile);
fread(&Header.biCompression, sizeof(Header.biCompression), 1, BMPFile);
fread(&Header.biSizeImage, sizeof(Header.biSizeImage), 1, BMPFile);
fread(&Header.biXPelsPerMeter, sizeof(Header.biXPelsPerMeter), 1, BMPFile);
fread(&Header.biYPelsPerMeter, sizeof(Header.biYPelsPerMeter), 1, BMPFile);
fread(&Header.biClrUsed, sizeof(Header.biClrUsed), 1, BMPFile);
fread(&Header.biClrImportant, sizeof(Header.biClrImportant), 1, BMPFile);
fseek(BMPFile,Header.OffBits,SEEK_SET) ;
printf("\nType:%hd and Type in %x\n", Header.Type,Header.Type);
printf("Size:%ld\n", Header.Size);
printf("Reserve1:%hd\n", Header.Reserve1);
printf("Reserve2:%hd\n", Header.Reserve2);
printf("OffBits:%ld\n", Header.OffBits);
printf("biSize:%ld\n", Header.biSize);
printf("Width: %ld\n", Header.biWidth);
printf("Height: %ld\n", Header.biHeight);
printf("biPlanes:%hd\n", Header.biPlanes);
printf("biBitCount:%hd\n", Header.biBitCount);
printf("biCompression:%ld\n", Header.biCompression);
printf("biSizeImage:%ld\n", Header.biSizeImage);
printf("biXPelsPerMeter:%ld\n", Header.biXPelsPerMeter);
printf("biYPelsPerMeter:%ld\n", Header.biYPelsPerMeter);
printf("biClrUsed:%ld\n", Header.biClrUsed);
printf("biClrImportant:%ld\n\n", Header.biClrImportant);
wBytesPerRow =Header.biWidth/8;
bAdditionalBitsPerRow = Header.biWidth % 8;
bPadding = (4 - ((wBytesPerRow + (bAdditionalBitsPerRow?1:0) ) % 4 ) ) %4;
HeaderBytes = Header.biWidth/8 ;
for(Vertical = 0 ; Vertical < Header.biHeight ; Vertical ++)
{
printf("Sr. No. %d \n",Vertical) ;
scanf("%c",&input) ;
if(input =='r' || input =='R' ) // Reverse Direction
{
// fseek(BMPFile,((4*968) + 3), SEEK_SET );
SendPixelValues() ;
}
if(input =='f' || input =='F' ) // Forward Direction
SendPixelValues() ;
printf("\n") ;
}
fclose(BMPFile);
return 0;
}
unsigned int bAdditionalBitsPerRowCount =
0,bPaddingCount=0; void SendPixelValues() {
for(Horizontal = 0 ; Horizontal < HeaderBytes ; Horizontal++)
{
fread(&pixelValue, sizeof(pixelValue), 1, BMPFile);
printf("0x%x ",pixelValue) ;
}
if(bAdditionalBitsPerRow > 0)
{
fread(&DummyValueRead , sizeof(DummyValueRead ), 1, BMPFile);
bAdditionalBitsPerRow++;
printf("bAdditionalBitsPerRowCount %d",bAdditionalBitsPerRowCount);
}
for(Horizontal = 0 ; Horizontal < bPadding; Horizontal++)
{
fread(&DummyValueRead , sizeof(DummyValueRead ), 1, BMPFile);
bPaddingCount++;
}
printf("bPaddingCount = %d",bPaddingCount) ;
}
但是我该怎么做:
my($stdout, $stderr, $exit) = $ssh->cmd("ls -al /home/mydir");
使用此Perl模块执行此操作的任何方法?
答案 0 :(得分:4)
-p
的{{1}}选项完成了您想要的操作(如果存在则没有错误),所以类似:
mkdir