2012-10-19 33 views
0

我想在emacs中使用powershell,但似乎emacs中的powershell是塊緩衝的。例如,當我編寫這樣一個簡單的C程序時:如何在Windows emacs中爲powershell進行行緩衝

int main() 
{ 
printf("input the number of a value: \n"); 
scanf("%d", &num); 
} 

我編譯它並使它在emacs下的Powershell中運行。直到我輸入一個數字並輸入Enter,它纔會打印出行input the number of a value:。 c程序在emacs之外的powershell中運行良好。我的問題是如何運行emacs中緩衝的PowerShell產品線?

編輯我使用Powershell.el

回答

0

您的fscanf之前需要fflush

+0

當我在'fscanf'之前'fflush'時,它會刷新兩次,並且有兩個完全相同的輸出。 – toolchainX

0

這對我的作品與eshell

#include <stdio.h> 

int main() { 
    int num; 
    printf("input the number:\n"); 
    fflush(stdout); 
    scanf("%d", &num); 
    printf("inc: %d\n", num + 1); 
} 

我無法重現powershell.el您的問題,因爲我看到了另一個問題:它不會等待輸入,「讀取」 0代替,版畫「 inc:1「並退出。

+0

是你的答案嗎?或者你遇到同樣的問題?我在powershell下的emacs中運行你的代碼。它像你所描述的一樣:它不等待輸入,「讀取」0代替,打印「inc:1」並退出。 – toolchainX

+0

它適用於'GNU Emacs for windows'中包含的程序cmdproxy,或許應該在powershell.el中完成 – toolchainX

+0

這是一個部分答案:問題中的代碼的行爲與編譯時描述的完全相同,從'eshell'運行(我還必須聲明'int num',否則它不會編譯)。我發佈的代碼在'eshell'中運行,並且按照預期運行。 'powershell.el'的問題必須是一個單獨的問題。 – Dmitry