crontab tee命令不会将stdout写入txt文件,而是将其清除[python脚本]

时间:2018-11-30 16:23:58

标签: python linux cron tee

我有一个用于python脚本的crontab命令,该命令可在目录中打印出符合特定条件的文件。该脚本在for循环中打印出文件。然后,我通过该管道将stdout发送到另一个目录中的文件,然后通过另一个管道删除这些文件。

这是命令:

public async void ConvertToImage(Stream fileStream) //Pass PDF stream
{
StorageFile file = null;
//Creates file picker to choose PDF file.
FileOpenPicker filePicker = new FileOpenPicker();

filePicker.FileTypeFilter.Add(".pdf");

filePicker.ViewMode = PickerViewMode.Thumbnail;

filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

filePicker.SettingsIdentifier = "picker1";

filePicker.CommitButtonText = "Open Pdf File";
//Open file picker option
file = await filePicker.PickSingleFileAsync();

// Load selected PDF file from the file picker.
PdfDocument pdfDocument = await PdfDocument.LoadFromFileAsync(file);

if (pdfDocument != null && pdfDocument.PageCount > 0)
{
for (int pageIndex = 0; pageIndex < pdfDocument.PageCount; pageIndex++)
{
//Get page from a PDF file.
var pdfPage = pdfDocument.GetPage((uint)pageIndex);

if (pdfPage != null)
{
//Create temporary folder to store images.
StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
//Create image file.
StorageFile destinationFile = await KnownFolders.CameraRoll.CreateFileAsync(Guid.NewGuid().ToString() + ".jpg");

if (destinationFile != null)
{
IRandomAccessStream randomStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite);
//Crerate PDF rendering options
PdfPageRenderOptions pdfPageRenderOptions = new PdfPageRenderOptions();

pdfPageRenderOptions.DestinationWidth = (uint)(300);
// Render the PDF's page as stream.
await pdfPage.RenderToStreamAsync(randomStream, pdfPageRenderOptions);

await randomStream.FlushAsync();
//Dispose the random stream
randomStream.Dispose();
//Dispose the PDF's page.
pdfPage.Dispose();
}
}
}
}
}

我在linux上手动测试了它,并输出到txt文件中。

但是,当cron作业(使用相同的命令,但用于不同的输出)运行时,它将清除相同的txt文件。

这似乎只是在cron中才能以一种怪异的方式进行。

我对cron和linux不太熟悉,因此不胜感激!

1 个答案:

答案 0 :(得分:0)

建议:将命令更改为tee -a myfile.txt

以下是“ tee”的文档:

http://man7.org/linux/man-pages/man1/tee.1.html