perlconsolecommandsystemvivado

How to launch and automatically feed commands to a software console?


This might seem like an already asked question but I found that it is a rare and still an open problem. My question is dependent on Vivado console but it is not related to Vivado console only, there can be any other console (consider Vivado console as an example only). If there are already solution available, I will be happy to redirected there.

Objective:

My aim is to build a vivado project using tcl commands.

I have a list of all the tcl commands available and I can run those commands very easily in the vivado console. There are two ways to do it in vivado console:

Method 1:

  1. Launch the command prompt
  2. run the following command to launch vivado console
vivado -mode tcl
  1. run the tcl commands one by one like:
set project_name "VIV_Project"
set user_project_dir C:/viv
create_project -force $project_name $user_project_dir/projects -part xczu11
  1. I can continue with all the commands until I execute the last command.
exit

Method 2:

Now there is another way to do it is to put all these commands in a one tcl script (tcl_script.tcl) and run one single command to build the entire project like this:

  1. Launch the command prompt
  2. run the following command to launch vivado console (batch mode) and run all the commands from a script:
vivado -mode batch -source tcl_script.tcl
  1. wait until script finishes execution

Now the trick part is "I do not want to give access of the tcl commands to anyone". I want them hidden. If I choose the method 1, commands needs to be entered manually onto the vivado console and so my tcl commands are open to the end user.

If I choose the Method 2, my commands are available in a tcl script that is again available in a directory. Vivado console does not support encrupted tcl scripts so I cannot do that either.

I am open to suggestion about how can I still execute my tcl commands without anyone knowing it? Ideally I want an executable that User can just click that run all the commands and then exit.

Experiments:

I have tried the following experiments that led to ask this question here:

Experiment 1:

I can create the executable of the perl script so I tried to use the perl script system() command:

system(vivado -mode tcl);
system(set project_name "VIV_Project");
system(set user_project_dir C:/viv);
system(create_project -force $project_name $user_project_dir/projects -part xczu11);
system(exit);

I was expecting it to launch the vivado console and then I thought that the next line would feed commands to the vivado console. And if every thing is according to the plan then I can buld an executable of the perl script and user can just launch the executable.

Now the issue with this method is that the system(vivado -mode tcl); commands never exits. It launches the vivado console and it stays there waiting for commands to be feed.

Experiment 2: I have tried to used the batch script to run the vivado console and then again ran into the same problem that once vivado is launched, the batch script is waiting for it to return.

This brings me to the question that I asked in the title (so I am going to discuss the details here):

How to launch and automatically feed commands to a software console?

Details on the original Question:

I am using perl script to run the commands via system().

  1. I want to the launch the vivado console using some environment (perl or anything else) whose executable I can create in the end.
  2. Then I want to give commands to vivado console from that environment. Issue with current perl approach is that system(vivado -mode tcl); commands launches the vivado but it never returns and meanwhile the vivado console is expecting some commands.

So how can I use an environment (perl or something) to launch a vivado console and then feed commands to that console?

Plus I am open to suggestion on how can I protect my tcl script? I have only provided one method here.

Thanks


Solution

  • It's unclear, but I think you're asking how to feed a string to a program's STDIN.

    use IPC::Run qw( run );
    
    my $script = "...";
    
    run [ "vivado", "-mode", "tcl" ],
       "<", \$script;
    

    Do realize that anything you send can easily be captured (e.g. by printing the value of $script or by replacing the vivado executable).