Skip to content

Log redirections too #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kurth4cker
Copy link

Problem

Currently when redirecting a commands inpout/output to a file, they are not logged. There is only command and arguments.

[INFO] CMD: cat

This patch adds a new type and functions which keeps file names with Nob_Fd and then prints like this:

[INFO] CMD: cat < input.txt > output.txt 2> error.txt

Here is a snippet uses new type.

#define NOB_EXPERIMENTAL_DELETE_OLD
#define NOB_IMPLEMENTATION
#include "nob.h"

int
main(int argc, char **argv)
{
    NOB_GO_REBUILD_URSELF_PLUS(argc, argv, "nob.h");

    Nob_Cmd *cmd = &(Nob_Cmd) { 0 };
    Nob_File fin = nob_file_open_for_read("pfork.1.scd");
    Nob_File fout = nob_file_open_for_write("pfork.1");
    nob_cmd_append(cmd, "scdoc");
    if (fin.fd == NOB_INVALID_FD
        || fout.fd == NOB_INVALID_FD
        || !nob_cmd_run_sync_redirect_file_and_reset(cmd, (Nob_Cmd_Redirect_File) {
            .fin = &fin,
            .fout = &fout,
    })) {
        nob_log(NOB_WARNING, "cannot run scdoc");
    }
    nob_file_close(fin);
    nob_file_close(fout);
}

Snippet is taken from my toy project:
https://github.com/kurth4cker/pfork/blob/635dca997d13bb1813adc5dc25030e287034ca72/nob.c

Notes

I'm not sure about this solution. I tried to not break current API. And it
is not complete yet. Please tell me your ideas about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant