 Hello, and welcome to this video by Chris from filmsbychris.com. Today we're looking at some C programming. Last time we looked at running system commands, today we're going to be looking at getting those and using the output of them. First of all, let's look at the poor man's version of it. System.C, you can come in here and you can see the basic example. We've got standardlib.h, we've got our main function and we're listing out our root directory. So let's go ahead and compile that with gcc, system.c-output, system. And then I can run that command and it gives me a list of the files. So if I wanted to use that somehow, I could always just say, hey, run that, put it into a temporary folder or file, file temp, and that will dump it into a file that I can later read, and we've looked at reading files in a previous tutorial. So that is one way to do that, but let's look at another option. Let's look at, and I already have typed out the code here, but we will go through it together. We're going to use the popen function here. So you need standardlib and standardio, if you don't have standardio, you can't use this. We're going to create a file variable here, like so, and then we're going to create a variable of 40 characters. That's what we're going to be storing, so you're going to want to think of the max size that you're going to be getting your output from, which might not be enough for what I'm about to do here. Let's check it out. But we're going to say, okay, so we've set up this variable, we're now going to say this variable equals, and we're going to use popen function. We're going to run our list on our root directory, and this is important here that you have this r. That means we're reading that information. And so now this is basically like a file, but it's not actually creating a file on your file system. It's like a temporary file in RAM. Now we're going to loop through that and read it. So we're using fgets, which we talked about in a previous video, and the size is going to be var size of var, so 40 characters, and we're going to loop through every character in the output here until it equals null. And we're going to print each character, okay? And in this particular case with list command, it is going to put each file name on its own line. So it's going to splay it a little bit different, but we're able to go through it here and utilize it. And then we can close out that temporary file and exit out of our program. So let's go ahead and use gcc, and we'll say command, or cmdoutput.c. Output that to cmdoutput, and we'll run that command dot slash boom, it now printed all our files. Let's go back into that file and change our command here. Let's try just, we'll change it to date and see what happens here. We'll recompile it. We will run it again, and there we go. We get the date output. But we're not just running that command and having it printed to the screen. We're actually running it, saving it to a temporary variable, and then looping through that so you could do whatever information you need, get it where information you need from that, and utilize it. So it's so much less when we're actually piping to a file and then we could read that file, but instead of actually creating a file, we're creating this like virtual file, if that makes any sense. Let's try another command. So let's do list dash this, this, okay. We'll compile that. We'll run that, and there is our output. From that particular list command. And that is it for this tutorial. Try to keep it short. Try to keep it simple. Again, C is not my best programming language. I know enough to get by. That's why I haven't done really any videos on it in the past, but I figured it was time I did something on it. So I'm hoping you're enjoying this series. If you know a better way of doing things, definitely let me know nicely in the comments below. Visit filmsbychrist.com. That's Chris of the K. There should be a link in the description. Or my Patreon page. Patreon.com forward slash metalx1000. I'll link to that in the description as well. If you'd like to support me, if you can't support me financially, think about liking, sharing, subscribing, commenting, all that fun stuff. And I hope that you have a great day.