Questions tagged [freopen]

freopen reopens a stream with a different file or mode.

Reuses stream to either open the file specified by filename or to change its access mode.

Reference: freopen

105 questions
0
votes
1 answer

Why it is faster writing a file which is freopened with stdout?

When executed on Windows, this test code: #define _CRT_SECURE_NO_WARNINGS #include #include #include int main() { // The clock() function returns an approximation of processor time used by the program. // The …
vertextao
  • 63
  • 8
0
votes
1 answer

How to redirects to the sandbox use "printf" in iOS?

In iOS development, I would like to test the output of the log to the local file. Use the redirection can be done to "NSLog" output to the file, but if I use the "printf" output when the use freopen([logFilePath…
David
  • 1
  • 2
0
votes
1 answer

Reopen stdout to a regular file for a linux daemon?

I understand that a daemon should not write to stdout (and stderr) because that wouldn't be available once detached from the controlling terminal. But can I reopen stdout to a regular file, so that all my original logging will still work? This would…
qweruiop
  • 3,156
  • 6
  • 31
  • 55
0
votes
1 answer

C - Terminal Write and Output to a Text File

I am a student taking an introductory C course and have our first C midterm coming up. Our test environment would store our actions and printf output to a text file. However, our TA suggested we write to a file ourselves using fprintf just…
0
votes
1 answer

Swift stderr and stout into single file

For an iPhone app, I need to collect debugging data into a file to be sent to an online service for analysis. This works fine by diverting the stderr output to a file handle and sending the file when appropriate. (NSLog output also ends up in…
Mundi
  • 79,884
  • 17
  • 117
  • 140
0
votes
1 answer

Write to subdirectory using freopen

I am trying to write out to files inside subdirectories using freopen: freopen("output/output-1.txt", "w", stdout); I have tried changing it to output to the current directory and it works. It terminates without errors when the target output file…
nerraruzi
  • 108
  • 8
0
votes
3 answers

Output into file and command line

I read about freopen to redirect all printf to a file, but I would like the output to be printed on the screen as well. Is there an easy way to redirect the printfs to a file and get the cmd line output? Thanks!
Framester
  • 33,341
  • 51
  • 130
  • 192
0
votes
0 answers

Freopen Refuses to Append to File Just Overwrites

I'm trying to make a shell in C. Everything works except file redirection. I think my code looks correct and I've tried about everything to get it working. The problem is that when the user inputs >> (ex. ls -l >> foo.txt) it's supposed to append to…
ComicStix
  • 240
  • 3
  • 14
0
votes
2 answers

How to redirect stdout and stdin in a given file using argv in C

I want to redirect stdout and stdin in a specific file which would be given in argv array. For instance when I enter a command like - ./shell ls > test it should be redirected to the "test" file, now I am bit confuse because without writing any code…
Ravi Vyas
  • 137
  • 1
  • 4
  • 19
0
votes
1 answer

Trying to use freopen but for two different files

I am trying using freopen() to print to two different files. is it possible? NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDir = [paths objectAtIndex: 0]; NSString *docFile = [docDir…
josef
  • 1,632
  • 1
  • 11
  • 16
0
votes
3 answers

why scanf skips '\n' in freopen function?

I'm using freopen function to read files. But when i use scanf statement to scan integers, it skips '\n' character. How can i avoid skipping '\n' by scanf.
0
votes
0 answers

Function freopen() does not write in file

I have next simple code: #include #include int main(int argc, char *argv[]) { FILE *fout; fout = freopen("stdout.txt", "w", stdout); Py_Initialize(); PyRun_SimpleString("print('Message')"); Py_Finalize(); …
0
votes
1 answer

Redirect stdin to provide no input at all?

In another question I asked I realized I want to redirect stdin but have it provide absolutely no input. For example, I want a call to getchar() to hang forever. I would then like to terminate the application by sending a kill signal. I tried…
boltup_im_coding
  • 6,345
  • 6
  • 40
  • 52
0
votes
1 answer

freopen_s("conout$") and fclose

Visual C++ is reporting that an invalid parameter was passed to fclose, that parameter being the FILE* returned by freopen_s: #include #include int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR…
NmdMystery
  • 2,778
  • 3
  • 32
  • 60
0
votes
1 answer

Strange Behavoir from freopen() and streams

EDIT: I've managed to narrow down the problem, but it still doesn't make much sense to me. My code becomes 8 lines: int savedOut = dup(1); printf("Changing the outstream to process.txt!") if ( freopen("process.txt", "w"m stdout) == NULL) …
Dan Brenner
  • 880
  • 10
  • 23